[PR #3583] [MERGED] Fix: Complete graceful Telegram bot shutdown and concurrency hardening #5457

Closed
opened 2026-10-31 20:47:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/3583
Author: @OleksandrParshyn
Created: 11/1/2025
Status: ✅ Merged
Merged: 11/1/2025
Merged by: @MHSanaei

Base: main ← Head: main


📝 Commits (2)

  • a9db70f Fix: Invoke service.StopBot() in signal handlers
  • e1fd563 Merge pull request #1 from OleksandrParshyn/OleksandrParshyn-patch-2

📊 Changes

1 file changed (+8 additions, -0 deletions)

View changed files

📝 main.go (+8 -0)

📄 Description

Description

This comprehensive fix addresses the Telegram bot conflict (409) during panel restarts and ensures robust thread safety in bot operation.

Changes

  1. Graceful Shutdown (main.go):
    • Added calls to service.StopBot() in main.go for both SIGHUP (restart) and service shutdown, ensuring the bot's Long Polling stops before the process is terminated/restarted.
  2. Robust Synchronization (tgbot.go):
    • Introduced botWG sync.WaitGroup to replace unreliable time.Sleep(), guaranteeing explicit waiting for the Long Polling goroutine to exit cleanly.
    • Added tgBotMutex sync.Mutex and logic to protect concurrent access to the global botCancel variable in tgbot.go.
    • Modified Tgbot.OnReceive() to correctly use context cancellation and manage botWG within the Long Polling goroutine.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/3583 **Author:** [@OleksandrParshyn](https://github.com/OleksandrParshyn) **Created:** 11/1/2025 **Status:** ✅ Merged **Merged:** 11/1/2025 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (2) - [`a9db70f`](https://github.com/MHSanaei/3x-ui/commit/a9db70f37edcf95f9fd238955c25987015d40871) Fix: Invoke service.StopBot() in signal handlers - [`e1fd563`](https://github.com/MHSanaei/3x-ui/commit/e1fd5635bffdbbcc1112aabff7bcac0275d0f029) Merge pull request #1 from OleksandrParshyn/OleksandrParshyn-patch-2 ### 📊 Changes **1 file changed** (+8 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `main.go` (+8 -0) </details> ### 📄 Description ## Description This comprehensive fix addresses the Telegram bot conflict (409) during panel restarts and ensures robust thread safety in bot operation. ## Changes 1. **Graceful Shutdown (main.go):** * Added calls to `service.StopBot()` in `main.go` for both `SIGHUP` (restart) and service shutdown, ensuring the bot's Long Polling stops before the process is terminated/restarted. 2. **Robust Synchronization (tgbot.go):** * Introduced `botWG sync.WaitGroup` to replace unreliable `time.Sleep()`, guaranteeing explicit waiting for the Long Polling goroutine to exit cleanly. * Added `tgBotMutex sync.Mutex` and logic to protect concurrent access to the global `botCancel` variable in `tgbot.go`. * Modified `Tgbot.OnReceive()` to correctly use context cancellation and manage `botWG` within the Long Polling goroutine. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:47:06 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5457
No description provided.