Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for Error: Receive is called after Client destroy #76

Open
comerc opened this issue Mar 22, 2021 · 2 comments
Open

Workaround for Error: Receive is called after Client destroy #76

comerc opened this issue Mar 22, 2021 · 2 comments

Comments

@comerc
Copy link
Contributor

comerc commented Mar 22, 2021

Hack of tdlib.go for DestroyInstance()

var IsClosed = false

func NewClient(config Config) *Client {
  // ...
  go func() {
    for !IsClosed {
      // get update
      updateBytes := client.Receive(10)
      // ...
    }
  }()
  // ...
}

usage:

  tdlib.IsClosed = true
  time.Sleep(1 * time.Second)
  client.DestroyInstance()

Снимок экрана от 2021-03-22 00-50-48

https://core.telegram.org/tdlib/docs/td__json__client_8h.html

@comerc
Copy link
Contributor Author

comerc commented Mar 22, 2021

Solution by @levlam

"Receive is called after Client destroy" is always a bug of those, who uses TDLib. You should move call to client.DestroyInstance() to the thread, which calls receive, instead of testing your luck with Sleep.

You can also use new JSON interface (td_create_client_id/td_send/td_receive), which removes possibility to do this bug.

@comerc
Copy link
Contributor Author

comerc commented Mar 22, 2021

See also tdlib/td#1394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant