Skip to content

Conversation

vadlml
Copy link

@vadlml vadlml commented Aug 27, 2025

Description

Fixes connection management issues in the MCP server's lifespan handler that could cause crashes during shutdown.

Changes

  • Add connection state tracking to prevent disconnect errors
  • Only attempt disconnect if client was successfully connected
  • Add exception handling for cleanup operations to prevent crashes
  • Resolves potential issues during server shutdown when connection fails

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🎨 Style update (formatting, renaming)
  • ♻️ Code refactor (no functional changes)
  • ⚡️ Performance improvement
  • ✅ Test update

Checklist

  • My code follows the code style of this project
  • I have checked my code and corrected any misspellings
  • I have commented my code, particularly in hard-to-understand areas

Related Issues

Additional Notes

This is a defensive programming fix that improves the reliability of the MCP server. The change is backward compatible and only affects the cleanup behavior during shutdown. Users will experience more stable server operation,
especially in environments with network issues or configuration problems.

- Add connection state tracking to prevent disconnect errors
- Only attempt disconnect if client was successfully connected
- Add exception handling for cleanup operations to prevent crashes
- Resolves potential issues during server shutdown when connection fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server crashes during shutdown when Telegram connection fails
1 participant