aspnetcore: Unknown disconnect happened and "ThrowInvalidOperationException_BackpressureDeadlock"

coordserver.log

Describe the bug

When I send several small message from signalr client to signalr hub,sometimes will raise a disconnect event. Message package is very small: 40B more or less , one per millisecond . The hub side do some time-consuming operations, 2 second in one message process operation。

When disconnect happened, the exception is null:2019-05-31 22:06:36,494 [6] DEBUG (null) CoordServer.Hubs.ServerHub >>> OnDisconnectedAsync Start, exception: (null)

or :2019-05-31 22:13:40,699 [23] ERROR (null) Microsoft.AspNetCore.SignalR.HubConnectionHandler >>> Error when processing requests. System.InvalidOperationException: Advancing examined to the end would cause pipe to deadlock because FlushAsync is waiting. at System.IO.Pipelines.ThrowHelper.ThrowInvalidOperationException_BackpressureDeadlock() at System.IO.Pipelines.Pipe.AdvanceReader(BufferSegment consumedSegment, Int32 consumedIndex, BufferSegment examinedSegment, Int32 examinedIndex) at System.IO.Pipelines.Pipe.AdvanceReader(SequencePosition& consumed, SequencePosition& examined) at System.IO.Pipelines.Pipe.DefaultPipeReader.AdvanceTo(SequencePosition consumed, SequencePosition examined) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.DispatchMessagesAsync(HubConnectionContext connection) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.RunHubAsync(HubConnectionContext connection).

From these links , I thought it maybe something about the size of ApplicationMaxBufferSize , but

Today SignalR needs to buffer the entire message before it calls your hub and it doesn’t start consuming the buffer until it seems an entire message.

In my program, the message size is so small, why I still met this error? Any helps? Thanks!

2266 8142 2322 5307

Additional context

Microsoft.AspNetCore.SignalR.Client 1.1.0 Microsoft.NETCore.App 2.2.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Allow me to confirm: Is your answer to this error : “Error when processing requests. System.InvalidOperationException: Advancing examined to the end would cause pipe to deadlock because FlushAsync is waiting” ?Thanks.

Yes, this exception has been removed completely from 3.0.

We no longer throw this error in 3.0. There is still a maximum message size, but it is configurable (and docs will be updated).

But I still did not find out the reason why this happened:

2019-06-06 19:39:34,256 [6] ERROR (null) Microsoft.AspNetCore.SignalR.HubConnectionHandler >>> Error when processing requests. System.InvalidOperationException: Advancing examined to the end would cause pipe to deadlock because FlushAsync is waiting. at System.IO.Pipelines.ThrowHelper.ThrowInvalidOperationException_BackpressureDeadlock() at System.IO.Pipelines.Pipe.AdvanceReader(BufferSegment consumedSegment, Int32 consumedIndex, BufferSegment examinedSegment, Int32 examinedIndex) at System.IO.Pipelines.Pipe.AdvanceReader(SequencePosition& consumed, SequencePosition& examined) at System.IO.Pipelines.Pipe.DefaultPipeReader.AdvanceTo(SequencePosition consumed, SequencePosition examined) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.DispatchMessagesAsync(HubConnectionContext connection) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.RunHubAsync(HubConnectionContext connection)

I really did not send a huge message, and every message I send to Hub just in 40B more or less.

Hi , I know, the reason of the first disconnect exception: When I modified the log level from info ->debug, I got this : Client timeout (30021ms) elapsed without receiving a message from the client. Closing connection. Then, I will get this exception: DEBUG (null) CoordServer.Hubs.ServerHub >>> OnDisconnectedAsync Start, exception: (null)

This is because the Hub function “MessageBoxGetList” is a time-consuming function, the DefaultClientTimeoutInterval is 30 seconds, So If my Hub got 16 message (every message cost 2s) in one time , this exception will appear.