Arman92 / go-tdlib

Golang Telegram TdLib JSON bindings
GNU General Public License v3.0
435 stars 101 forks source link

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

Open comerc opened 3 years ago

comerc commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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