Fix null ref in DisposeAsync on ConnectionState
This commit is contained in:
parent
c1a4b25a66
commit
0abac4a20d
|
|
@ -51,13 +51,13 @@ namespace Microsoft.AspNetCore.Sockets.Internal
|
|||
RequestId = null;
|
||||
|
||||
// If the application task is faulted, propagate the error to the transport
|
||||
if (ApplicationTask.IsFaulted)
|
||||
if (ApplicationTask?.IsFaulted == true)
|
||||
{
|
||||
Connection.Transport.Output.TryComplete(ApplicationTask.Exception.InnerException);
|
||||
}
|
||||
|
||||
// If the transport task is faulted, propagate the error to the application
|
||||
if (TransportTask.IsFaulted)
|
||||
if (TransportTask?.IsFaulted == true)
|
||||
{
|
||||
Application.Output.TryComplete(TransportTask.Exception.InnerException);
|
||||
}
|
||||
|
|
@ -65,8 +65,8 @@ namespace Microsoft.AspNetCore.Sockets.Internal
|
|||
Connection.Dispose();
|
||||
Application.Dispose();
|
||||
|
||||
applicationTask = ApplicationTask;
|
||||
transportTask = TransportTask;
|
||||
applicationTask = ApplicationTask ?? applicationTask;
|
||||
transportTask = TransportTask ?? transportTask;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Sockets.Internal;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -101,6 +100,20 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
await state.DisposeAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DisposeInactiveConnection()
|
||||
{
|
||||
var connectionManager = CreateConnectionManager();
|
||||
var state = connectionManager.CreateConnection();;
|
||||
|
||||
Assert.NotNull(state.Connection);
|
||||
Assert.NotNull(state.Connection.ConnectionId);
|
||||
Assert.NotNull(state.Connection.Transport);
|
||||
|
||||
await state.DisposeAsync();
|
||||
Assert.Equal(state.Status, ConnectionState.ConnectionStatus.Disposed);
|
||||
}
|
||||
|
||||
private static ConnectionManager CreateConnectionManager()
|
||||
{
|
||||
return new ConnectionManager(new Logger<ConnectionManager>(new LoggerFactory()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue