diff --git a/webhook_handler.go b/webhook_handler.go index 1734a3f..3febad1 100644 --- a/webhook_handler.go +++ b/webhook_handler.go @@ -32,7 +32,13 @@ func (b *Bot) WebhookHandler() http.HandlerFunc { case <-req.Context().Done(): b.error("some updates lost, ctx done") return + default: + } + + select { case b.updates <- update: + case <-req.Context().Done(): + b.error("failed to send update, ctx done") } } } diff --git a/webhook_handler_test.go b/webhook_handler_test.go index 1f759a6..c63d2ea 100644 --- a/webhook_handler_test.go +++ b/webhook_handler_test.go @@ -170,6 +170,7 @@ func TestWebhookHandler_ContextDone(t *testing.T) { case <-bot.updates: t.Fatal("Did not expect update to be sent to bot.updates channel") default: + // Expected outcome, context was cancelled before sending the update } if len(errorsHandler.errors) == 0 {