From 8a56c07e8b70a4c992048da7ffce48bc318397c7 Mon Sep 17 00:00:00 2001 From: Saddam Azy <59659668+myxzlpltk@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:10:36 +0700 Subject: [PATCH 1/2] Accept context when stopping updater --- ext/updater.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/updater.go b/ext/updater.go index e664617..4cda258 100644 --- a/ext/updater.go +++ b/ext/updater.go @@ -244,10 +244,10 @@ func (u *Updater) Idle() { // // When using long polling, Stop() will wait for the getUpdates call to return, which may cause a delay due to the // request timeout. -func (u *Updater) Stop() error { +func (u *Updater) Stop(ctx context.Context) error { // Stop any running servers. if u.webhookServer != nil { - err := u.webhookServer.Shutdown(context.Background()) + err := u.webhookServer.Shutdown(ctx) if err != nil { return fmt.Errorf("failed to shutdown server: %w", err) } From d598261d6f272ed7947ccb2f444f961d3b397a19 Mon Sep 17 00:00:00 2001 From: Paul Larsen Date: Thu, 6 Nov 2025 23:24:23 +0100 Subject: [PATCH 2/2] Fix tests --- ext/updater_test.go | 8 ++++---- samples/echoMultiBot/main.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ext/updater_test.go b/ext/updater_test.go index a64a552..308f657 100644 --- a/ext/updater_test.go +++ b/ext/updater_test.go @@ -376,7 +376,7 @@ func TestUpdaterAllowsWebhookDeletion(t *testing.T) { return } - err = u.Stop() + err = u.Stop(context.Background()) if err != nil { t.Errorf("failed to stop updater: %v", err) return @@ -430,7 +430,7 @@ func TestUpdaterSupportsTwoPollingBots(t *testing.T) { return } - err = u.Stop() + err = u.Stop(context.Background()) if err != nil { t.Errorf("failed to stop updater: %v", err) return @@ -478,7 +478,7 @@ func TestUpdaterThrowsErrorWhenSameLongPollAddedTwice(t *testing.T) { return } - err = u.Stop() + err = u.Stop(context.Background()) if err != nil { t.Errorf("failed to stop updater: %v", err) return @@ -529,7 +529,7 @@ func TestUpdaterSupportsLongPollReAdding(t *testing.T) { return } - err = u.Stop() + err = u.Stop(context.Background()) if err != nil { t.Errorf("failed to stop updater: %v", err) return diff --git a/samples/echoMultiBot/main.go b/samples/echoMultiBot/main.go index 91d40c5..ab2358c 100644 --- a/samples/echoMultiBot/main.go +++ b/samples/echoMultiBot/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "log" "log/slog" @@ -186,7 +187,7 @@ func stopAll(b *gotgbot.Bot, ctx *ext.Context, updater *ext.Updater) error { // We stop the updater in a separate goroutine, otherwise it would be stuck waiting for itself. go func() { - err = updater.Stop() + err = updater.Stop(context.Background()) if err != nil { ctx.EffectiveMessage.Reply(b, fmt.Sprintf("Failed to stop updater: %s", err.Error()), nil) return