in src/Microsoft.Azure.Relay/HybridConnectionListener.cs [341:383]
public async Task CloseAsync(CancellationToken cancellationToken)
{
try
{
List<HybridConnectionStream> clients;
lock (this.ThisLock)
{
if (this.closeCalled)
{
return;
}
RelayEventSource.Log.ObjectClosing(this);
this.closeCalled = true;
// If the input queue is empty this completes all pending waiters with null and prevents
// any new items being added to the input queue.
this.connectionInputQueue.Shutdown();
// Close any unaccepted rendezvous. DequeueAsync won't block since we've called connectionInputQueue.Shutdown().
clients = new List<HybridConnectionStream>(this.connectionInputQueue.PendingCount);
HybridConnectionStream stream;
while ((stream = this.connectionInputQueue.DequeueAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()) != null)
{
clients.Add(stream);
}
}
await this.controlConnection.CloseAsync(cancellationToken).ConfigureAwait(false);
clients.ForEach(client => ((WebSocketStream)client).Abort());
RelayEventSource.Log.ObjectClosed(this);
}
catch (Exception e) when (!Fx.IsFatal(e))
{
RelayEventSource.Log.ThrowingException(e, this);
throw;
}
finally
{
this.connectionInputQueue.Dispose();
}
}