Skip to content

SslStream ObjectDisposedException causes reconnection loop in .NET 10 with ASP.Net 10/3.16.0 client #358

Description

@chriscameron-vertexinc

Describe the bug
We are experiencing a reconnection loop due to an unhandled System.ObjectDisposedException on SslStream in our application, using the latest Pulsar.Client (3.16.0), .NET 10, and official ASP.NET 10 Docker base images. This appears to leave the application stuck in a reconnection cycle instead of recovering or failing gracefully.

Exception details

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Security.SslStream'.
  at System.Net.Security.SslStream.<ThrowIfExceptional>g__ThrowExceptional|131_0(ExceptionDispatchInfo e)
  at Pipelines.Sockets.Unofficial.StreamConnection.AsyncStreamPipe.CopyFromWritePipeToStream()
  at System.IO.Pipelines.PipeWriter.CopyFromAsync(Stream source, CancellationToken cancellationToken)
  at Pulsar.Client.Common.Commands.serializeSimpleCommand@44-1.MoveNext()
  at <StartupCode$Pulsar-Client>.$ClientCnx.clo@302-10.MoveNext()

Environment:

  • .NET 10
  • Pulsar.Client 3.16.0
  • Official ASP.NET 10 Docker image

Observed behavior

  • The connection drops, triggering a reconnect loop.
  • The reconnect logic appears to run repeatedly (see ConnectionHandler.fs, ConnectionPool.fs, ClientCnx.fs), but we never recover nor get a permanent failure.
  • Exception is thrown in the context of SslStream/Pipelines, possibly after dispose.

Relevant code (semantic search references):

Possible cause

  • The reconnect logic with SslStream/Sockets appears to trigger after an ObjectDisposedException that isn't fully handled, leading to continuous attempts.
  • See dotnet/runtime #103499 for background around SslStream behavior on disconnection.

Expected behavior

  • Client should either recover, or escalate to a permanent failure instead of looping on reconnect when SslStream is disposed.

Steps to reproduce

  1. Deploy an application using ASP.NET 10 and Pulsar.Client 3.16.0.
  2. Disrupt broker connection so SslStream gets disposed (e.g., network drop or broker shutdown).
  3. Observe client logs for reconnect loop with ObjectDisposedException.

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