tucnak / telebot

Telebot is a Telegram bot framework in Go.
MIT License
4.02k stars 467 forks source link

webhook: panic: close of closed channel #584

Closed archimed-shaman closed 8 months ago

archimed-shaman commented 1 year ago

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/telebot.v3@v3.1.3/webhook.go:155
gopkg.in/telebot%2ev3.(*Webhook).Poll.func1(0x0?)
    /go/pkg/mod/gopkg.in/telebot.v3@v3.1.3/webhook.go:142 +0x34
created by gopkg.in/telebot%2ev3.(*Webhook).Poll
    /go/pkg/mod/gopkg.in/telebot.v3@v3.1.3/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

suntong commented 1 year ago

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?

ayasechan commented 11 months ago

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

Dementor316 commented 11 months ago

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.

demget commented 8 months ago

641

tarik02 commented 5 months ago

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

kyrylo commented 5 months ago

I confirm this is not fixed.

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