When stopping the event monitor (Ctrl+C or timeout), the subscription deletion was happening twice, causing a 500 error on the second attempt:
🧹 Cleaning up subscription: sub_fa77ad23-289
✅ Subscription deleted
🧹 Cleaning up subscription: sub_fa77ad23-289 ← DUPLICATE!
⚠️ Failed to delete subscription: 500 ← ERROR!
Double-call scenario:
- ✅ Signal handler (Ctrl+C) → Calls
stop()→ Deletes subscription (200 OK) - ✅ Finally block (Python cleanup) → Calls
stop()again → 500 error (already deleted)
The issue was that sys.exit(0) in the signal handler doesn't prevent Python's finally block from executing, leading to stop() being called twice.
Added an idempotency guard to prevent stop() from executing twice:
def stop(self):
"""Stop monitoring and cleanup"""
# Guard against double-call
if hasattr(self, '_stopped') and self._stopped:
return # Already stopped, do nothing
self._stopped = True
# ... rest of cleanup code- First call:
_stoppedis not set → Proceeds with cleanup - Second call:
_stoppedis True → Returns immediately (no-op)
Server logs:
[23:21:57] 200 - 1.838099ms DELETE /api/v1/subscriptions/sub_fa77ad23-289
[23:21:57] 500 - 11.941µs DELETE /api/v1/subscriptions/sub_fa77ad23-289
Server logs:
[23:35:21] 200 - 1.821782ms DELETE /api/v1/subscriptions/sub_b8a4d9e4-161
Only ONE DELETE request! No 500 error!
✅ Clean shutdown - No confusing error messages
✅ Idempotent - Safe to call stop() multiple times
✅ Efficient - Reduces unnecessary API calls
✅ Professional - Better user experience
Tested with multiple scenarios:
- ✅ Ctrl+C shutdown
- ✅ Timeout termination (SIGTERM)
- ✅ Normal exit
All scenarios now show single deletion with 200 OK status.
event_monitor.py(Lines 394-397): Added_stoppedguard
Full technical details in: BUGFIX_DOUBLE_DELETION.md
October 5, 2025
✅ FIXED AND VERIFIED