Skip to content

Make sure that channel is transitioned to the closed state before returning connection to the pool #5804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal abstract class TransportDuplexSessionChannel : TransportOutputChannel,
{
private bool _isInputSessionClosed;
private bool _isOutputSessionClosed;
private bool _releasingConnection;
private Uri _localVia;
private ChannelBinding _channelBindingToken;

Expand Down Expand Up @@ -290,6 +291,11 @@ protected async Task CloseOutputSessionAsync(TimeSpan timeout)

protected override void OnAbort()
{
if (_releasingConnection)
{
// We are releasing the connection to the pool.
return;
}
ReturnConnectionIfNecessary(true, TimeSpan.Zero);
}

Expand Down Expand Up @@ -567,6 +573,9 @@ private void OnOutputSessionClosed(ref TimeoutHelper timeoutHelper)

if (releaseConnection)
{
// Call Abort() to ensure proper channel state before returning the connection to the pool.
_releasingConnection = true;
Abort();
ReturnConnectionIfNecessary(false, timeoutHelper.RemainingTime());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ private void SetupInnerChannelFaultHandler()
// NullReferenceException in this method or in the OnInnerChannelFaulted method;
// because this method accesses this.binder and OnInnerChannelFaulted accesses this.clientRuntime.
Binder.Channel.Faulted += OnInnerChannelFaulted;
Binder.Channel.Closed += OnInnerChannelClosed;
}

private void BindDuplexCallbacks()
Expand Down Expand Up @@ -1169,6 +1170,16 @@ private void OnInnerChannelFaulted(object sender, EventArgs e)
}
}

private void OnInnerChannelClosed(object sender, EventArgs e)
{
if (HasSession)
{
DispatchRuntime dispatchRuntime = ClientRuntime.DispatchRuntime;
}

Abort();
}

private void AddMessageProperties(Message message, OperationContext context)
{
if (_allowOutputBatching)
Expand Down
Loading