telebot icon indicating copy to clipboard operation
telebot copied to clipboard

webhook: panic: close of closed channel

Open archimed-shaman opened this issue 1 year ago • 3 comments

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

archimed-shaman avatar Mar 13 '23 08:03 archimed-shaman

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?

suntong avatar Apr 24 '23 23:04 suntong

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

ayasechan avatar Nov 29 '23 13:11 ayasechan

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.

Dementor316 avatar Dec 15 '23 15:12 Dementor316

#641

demget avatar Feb 21 '24 11:02 demget

It was not actually fixed, If you call Stop, you close the channel. And then, in waitForStop you cancel it the next time...

tarik02 avatar May 19 '24 16:05 tarik02

I confirm this is not fixed.

Please, reopen (the stacktrace is identical to the OP's stacktrace).

kyrylo avatar May 20 '24 08:05 kyrylo