telebot
telebot copied to clipboard
webhook: panic: close of closed channel
gopkg.in/telebot.v3 v3.1.3
Error:
panic: close of closed channel
goroutine 49 [running]:
gopkg.in/telebot%2ev3.(*Webhook).waitForStop(...)
/go/pkg/mod/gopkg.in/[email protected]/webhook.go:155
gopkg.in/telebot%2ev3.(*Webhook).Poll.func1(0x0?)
/go/pkg/mod/gopkg.in/[email protected]/webhook.go:142 +0x34
created by gopkg.in/telebot%2ev3.(*Webhook).Poll
/go/pkg/mod/gopkg.in/[email protected]/webhook.go:141 +0x1d9
Looks like this happens because stop
channel is closed in two places:
https://github.com/tucnak/telebot/blob/fbd35f210343604adb89e96859a9639d9366e966/bot.go#L222
https://github.com/tucnak/telebot/blob/fbd35f210343604adb89e96859a9639d9366e966/webhook.go#L123
Hi @archimed-shaman, would you share how you get this far please? I'm having troubles making webhook work for tucnak/telebot. Moreover, webhook does not need poller, right?
The reason for this problem is If you do not configure the Listen field poll function will directly call the waitForStop method to close the channel
When you call the Stop function, this function will call waitForStop for the second time closing the channel to cause panic
https://github.com/tucnak/telebot/blob/71ac2995cc5d7379c35fceb3b64ce2c693e79e0c/webhook.go#L131-L133
Am I correct in understanding that for an elegant solution to the problem, we simply do not need to call the Stop() method when terminating the bot process? If I don't call this method, no panic occurs, but how necessary is its invocation and how much can the absence of calling the Stop() method when using WebHooks lead to negative consequences? I would be grateful if someone could help me understand this issue.
#641
It was not actually fixed, If you call Stop
, you close the channel. And then, in waitForStop
you cancel it the next time...
I confirm this is not fixed.
Please, reopen (the stacktrace is identical to the OP's stacktrace).