Skip to content
Merged
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 @@ -168,6 +168,14 @@ private async Task ExecuteAsync(HttpContext context, ConnectionDelegate connecti
{
transport = HttpTransportType.WebSockets;
connection = await GetOrCreateConnectionAsync(context, options);

if (connection is not null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can this be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you attempt to connect with a connection id query string param that doesn't exist on this server instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method name is bad then, GetOrCreateOrNot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 this method name is >8 years old now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I blame myself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do too 😉

{
Log.EstablishedConnection(_logger);

// Allow the reads to be canceled
connection.Cancellation ??= new CancellationTokenSource();
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,37 @@ public async Task WebSocketConnectionClosingTriggersConnectionClosedToken()
}
}

[Fact]
public async Task ServerClosingClosesWebSocketConnection()
{
using (StartVerifiableLog())
{
var manager = CreateConnectionManager(LoggerFactory);
var connection = manager.CreateConnection();

var dispatcher = CreateDispatcher(manager, LoggerFactory);
var services = new ServiceCollection();
services.AddSingleton<TestConnectionHandler>();
var context = MakeRequest("/foo", connection, services);
SetTransport(context, HttpTransportType.WebSockets);

var builder = new ConnectionBuilder(services.BuildServiceProvider());
builder.UseConnectionHandler<TestConnectionHandler>();
var app = builder.Build();
var options = new HttpConnectionDispatcherOptions();
options.WebSockets.CloseTimeout = TimeSpan.FromSeconds(1);

var executeTask = dispatcher.ExecuteAsync(context, options, app);

// "close" server, since we're not using a server in these tests we just simulate what would be called when the server closes
await connection.DisposeAsync().DefaultTimeout();

await connection.ConnectionClosed.WaitForCancellationAsync().DefaultTimeout();

await executeTask.DefaultTimeout();
}
}

public class CustomHttpRequestLifetimeFeature : IHttpRequestLifetimeFeature
{
public CancellationToken RequestAborted { get; set; }
Expand Down