-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
The Listener.Run method currently leaks message sessions. Because the Client interface lacks a Close method, the listener exits—whether via context cancellation or error—without notifying the server. This results in "zombie" sessions and resource leaks on the scaleset API.
Proposed Changes
Update Client interface: Add Close(ctx context.Context) error to allow for graceful session termination.
Implement cleanup in Run: Use a defer block to ensure Close is called on exit.
Note: The cleanup uses context.Background() with a timeout because the primary ctx is likely already cancelled when the defer triggers.
type Client interface {
GetMessage(ctx context.Context, lastMessageID, maxCapacity int) (*scaleset.RunnerScaleSetMessage, error)
DeleteMessage(ctx context.Context, messageID int) error
Session() scaleset.RunnerScaleSetSession
Close(ctx context.Context) error // Added
}
func (l *Listener) Run(ctx context.Context, scaler Scaler) error {
defer func() {
// Ensure session cleanup even if parent context is cancelled
cleanupCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := l.client.Close(cleanupCtx); err != nil {
l.logger.Error("failed to close session", "error", err)
}
}()
for {
select {
case <-ctx.Done():
return ctx.Err()
default:
// ... processing logic ...
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels