go-tdlib icon indicating copy to clipboard operation
go-tdlib copied to clipboard

Workaround for Error: Receive is called after Client destroy

Open comerc opened this issue 4 years ago • 2 comments

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 avatar Mar 22 '21 08:03 comerc

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 avatar Mar 22 '21 08:03 comerc

See also https://github.com/tdlib/td/issues/1394

comerc avatar Mar 22 '21 08:03 comerc