[CSHARP-3462] Unobserved task exception on connection failure raises its head again Created: 09/Mar/21  Updated: 28/Oct/23  Resolved: 17/May/21

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: 2.12.0
Fix Version/s: 2.13.0

Type: Bug Priority: Major - P3
Reporter: Aristarkh Zagorodnikov Assignee: Mikalai Mazurenka (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Server 2019 x64
.NET Framework 4.8


Issue Links:
Depends
is depended on by CSHARP-3684 Unobserved task exception when connec... Closed

 Description   

It seems that CSHARP-1628 is with us again. Since upgrading to 2.12.0 we occasionally receive the following exception in our unobserved exception logger:

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.
 ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
ResponseMessage MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessage(int responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
ResponseMessage MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquiredConnection.ReceiveMessage(int responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol<TCommandResult>.Execute(IConnection connection, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.WireProtocol.CommandWireProtocol<TCommandResult>.Execute(IConnection connection, CancellationToken cancellationToken)
TResult MongoDB.Driver.Core.Servers.Server+ServerChannel.ExecuteProtocol<TResult>(IWireProtocol<TResult> protocol, ICoreSession session, CancellationToken cancellationToken)
TResult MongoDB.Driver.Core.Servers.Server+ServerChannel.Command<TResult>(ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable<Type1CommandMessageSection> commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action<IMessageEncoderPostProcessor> postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer<TResult> resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.Operations.CommandOperationBase<TCommandResult>.ExecuteProtocol(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.Operations.ReadCommandOperation<TCommandResult>.ExecuteAttempt(RetryableReadContext context, int attempt, long? transactionNumber, CancellationToken cancellationToken)
TResult MongoDB.Driver.Core.Operations.RetryableReadOperationExecutor.Execute<TResult>(IRetryableReadOperation<TResult> operation, RetryableReadContext context, CancellationToken cancellationToken) ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
int System.Net.Sockets.NetworkStream.Read(out byte[] buffer, int offset, int size)
void MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytes(Stream stream, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
IByteBuffer MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBuffer(CancellationToken cancellationToken) ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
int System.Net.Sockets.NetworkStream.Read(out byte[] buffer, int offset, int size)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace --- ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
ResponseMessage MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessage(int responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
ResponseMessage MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquiredConnection.ReceiveMessage(int responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol<TCommandResult>.Execute(IConnection connection, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.WireProtocol.CommandWireProtocol<TCommandResult>.Execute(IConnection connection, CancellationToken cancellationToken)
TResult MongoDB.Driver.Core.Servers.Server+ServerChannel.ExecuteProtocol<TResult>(IWireProtocol<TResult> protocol, ICoreSession session, CancellationToken cancellationToken)
TResult MongoDB.Driver.Core.Servers.Server+ServerChannel.Command<TResult>(ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable<Type1CommandMessageSection> commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action<IMessageEncoderPostProcessor> postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer<TResult> resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.Operations.CommandOperationBase<TCommandResult>.ExecuteProtocol(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
TCommandResult MongoDB.Driver.Core.Operations.ReadCommandOperation<TCommandResult>.ExecuteAttempt(RetryableReadContext context, int attempt, long? transactionNumber, CancellationToken cancellationToken)
TResult MongoDB.Driver.Core.Operations.RetryableReadOperationExecutor.Execute<TResult>(IRetryableReadOperation<TResult> operation, RetryableReadContext context, CancellationToken cancellationToken) ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
int System.Net.Sockets.NetworkStream.Read(out byte[] buffer, int offset, int size)
void MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytes(Stream stream, byte[] buffer, int offset, int count, CancellationToken cancellationToken)
IByteBuffer MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBuffer(CancellationToken cancellationToken) ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
int System.Net.Sockets.NetworkStream.Read(out byte[] buffer, int offset, int size)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---

It's of low priority, but I still believe you might want to know about this.



 Comments   
Comment by Githook User [ 17/May/21 ]

Author:

{'name': 'MikalaiMazurenka', 'email': '55145764+MikalaiMazurenka@users.noreply.github.com', 'username': 'MikalaiMazurenka'}

Message: CSHARP-3462: Unobserved task exception on connection failure raises its head again (#492)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/d8ab2f17e5880c279b64387cc43c03afd12d650a

Comment by Dmitry Lukyanov (Inactive) [ 11/Mar/21 ]

Thanks onyxmaster for your report, we will investigate this and come back to you.

Comment by Aristarkh Zagorodnikov [ 09/Mar/21 ]

On the other hand, it looks like it's a slightly different exception.

Generated at Wed Feb 07 21:45:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.