Implement comprehensive WebSocket subscription stability fixes
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled

- Resolved critical issues causing subscriptions to drop after 30-60 seconds due to unconsumed receiver channels.
- Introduced per-subscription consumer goroutines to ensure continuous event delivery and prevent channel overflow.
- Enhanced REQ parsing to handle both wrapped and unwrapped filter arrays, eliminating EOF errors.
- Updated publisher logic to correctly send events to receiver channels, ensuring proper event delivery to subscribers.
- Added extensive documentation and testing tools to verify subscription stability and performance.
- Bumped version to v0.26.2 to reflect these significant improvements.
This commit is contained in:
2025-11-06 18:21:00 +00:00
parent d604341a27
commit 581e0ec588
23 changed files with 3054 additions and 81 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"strings"
"sync"
"sync/atomic"
"time"
@@ -23,6 +24,7 @@ type Listener struct {
*Server
conn *websocket.Conn
ctx context.Context
cancel context.CancelFunc // Cancel function for this listener's context
remote string
req *http.Request
challenge atomicutils.Bytes
@@ -41,6 +43,9 @@ type Listener struct {
msgCount int
reqCount int
eventCount int
// Subscription tracking for cleanup
subscriptions map[string]context.CancelFunc // Map of subscription ID to cancel function
subscriptionsMu sync.Mutex // Protects subscriptions map
}
type messageRequest struct {
@@ -189,8 +194,9 @@ func (l *Listener) messageProcessor() {
return
}
// Process the message synchronously in this goroutine
l.HandleMessage(req.data, req.remote)
// Process the message in a separate goroutine to avoid blocking
// This allows multiple messages to be processed concurrently (like khatru does)
go l.HandleMessage(req.data, req.remote)
}
}
}