You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes the client.Close() API call does not complete in time and returns the "response catching timeout". As a fallback, I just close the listener when the timeout has happened, so new updates won't be handled. However, the receive() goroutine does not gracefully handle this, even though it's supposed to, and occasionally panics:
panic: send on closed channel
goroutine 15 [running]:
github.com/zelenin/go-tdlib/client.(*Client).receive(0xc00007ea00)
/opt/gone/pkg/mod/github.com/zelenin/go-tdlib@v0.1.0/client/client.go:98 +0x19a
created by github.com/zelenin/go-tdlib/client.NewClient
/opt/gone/pkg/mod/github.com/zelenin/go-tdlib@v0.1.0/client/client.go:69 +0x198
The code that causes the panic is:
for _, listener := range client.listenerStore.Listeners() {
if listener.IsActive() {
listener.Updates <- typ
} else {
needGc = true
}
}
The IsActive() and Close() calls themselves are protected with locks, so the isActive flag theoretically shouldn't be set when the listener.Updates channel is closed already. But it's still possible that the Close() call happens between the IsActive() check and the channel write operation. So a more robust mechanism is needed.
Sometimes the
client.Close()
API call does not complete in time and returns the "response catching timeout". As a fallback, I just close the listener when the timeout has happened, so new updates won't be handled. However, thereceive()
goroutine does not gracefully handle this, even though it's supposed to, and occasionally panics:The code that causes the panic is:
The
IsActive()
andClose()
calls themselves are protected with locks, so theisActive
flag theoretically shouldn't be set when thelistener.Updates
channel is closed already. But it's still possible that theClose()
call happens between theIsActive()
check and the channel write operation. So a more robust mechanism is needed.I propose a following pattern:
This way, the channel is guaranteed to remain open.
The text was updated successfully, but these errors were encountered: