Skip to content

Unhandled exception in unsubscribe from closeDueToPing #198

Open
@MattiasCL

Description

@MattiasCL

Had a process crash following a disconnect from the NATS server with this stack trace:

NATS.Client.NATSConnectionClosedException: Connection is closed.
   at NATS.Client.Subscription.unsubscribe(Boolean throwEx)
   at NATS.Client.AsyncSubscription.Unsubscribe()
   at STAN.Client.Connection.cleanupOnClose(Exception ex)
   at STAN.Client.Connection.closeDueToPing(Exception ex)
   at STAN.Client.Connection.pingServer(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers()

Had a brief look in the source code: cleanupOnClose only unsubscribes the ackSubscription and pingSubscription if the NATS connection isn't already closed, and unsubscribe throws if called on a closed subscription. The connection's internal mutex isn't held in between those checks, so my guess is that there's a chance for a data race with the connection closing between cleanupOnClose and unsubscribe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions