The Telegram bot library for Golang is not shutting down gracefully. When I stop the bot and restart it, I encounter conflict errors: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running.
Expected Behavior:
The bot should shut down cleanly, releasing any resources it's using. On restart, it should start without any conflicts.
Steps to Reproduce:
Run the provided Golang code.
Press Ctrl+C to stop the bot.
Run the code again.
Observe the conflict errors in the console output.
Code Snippet:
var configFile = flag.String("f", "../etc/bot.yaml", "the config file")
func main() {
flag.Parse()
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
var cfg config.Config
conf.MustLoad(*configFile, &cfg)
svcCtx, err := svc.NewServiceContext(&cfg)
if err != nil {
fmt.Println("the error:", err)
panic(fmt.Sprintf("failed to create service context: %v", err))
}
b, err := bot.New(svcCtx.Config.BotToken, bot.WithServerURL(svcCtx.Config.StartBotApi))
if err != nil {
panic(fmt.Sprintf("failed to create bot: %v", err))
}
fmt.Println("Bot started")
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
b.Start(ctx)
}()
wg.Wait()
<-ctx.Done()
fmt.Println("Shutting down the bot gracefully...")
fmt.Println("Bot stopped")
}
Errors
➜ cmd git:(main) ✗ go run .
Bot started
^CShutting down the bot gracefully...
Bot stopped
{"@timestamp":"2024-09-30T10:50:37.996+05:00","caller":"proc/shutdown.go:58","content":"Got signal 2, shutting down...","level":"info"}
➜ cmd git:(main) ✗ go run .
Bot started
2024/09/30 10:50:39 [TGBOT] [ERROR] error get updates, conflict, Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
2024/09/30 10:50:39 [TGBOT] [ERROR] error get updates, conflict, Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
2024/09/30 10:50:40 [TGBOT] [ERROR] error get updates, conflict, Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
2024/09/30 10:50:40 [TGBOT] [ERROR] error get updates, conflict, Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
2024/09/30 10:50:41 [TGBOT] [ERROR] error get updates, conflict, Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
Problem:
The Telegram bot library for Golang is not shutting down gracefully. When I stop the bot and restart it, I encounter conflict errors:
Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
.Expected Behavior:
The bot should shut down cleanly, releasing any resources it's using. On restart, it should start without any conflicts.
Steps to Reproduce:
Ctrl+C
to stop the bot.Code Snippet:
Errors