-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Log error when exception occurs during streaming #42283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BrennanConroy
merged 3 commits into
dotnet:main
from
campersau:signalrstreaminglogerror
Jun 22, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure should this one. cancellation failures shouldn't be logged as an error, maybe debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't see
!
. Or do you mean otherOperationCanceledException
s when!streamCts.IsCancellationRequested
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, @campersau. There is an
!
!!It is surprising that this wasn't logged already. Are we sure this isn't logged anywhere else? This really should just be calling
Log.FailedInvokingHubMethod(_logger, hubMethodInvocationMessage.Target, ex)
if we observe that an Exception is thrown from a streaming hub method without the client cancelling the invocation.I would assume the
!streamCts.IsCancellationRequested
by itself is sufficient to ensure that. I'm not sure about theChannelClosedException
. @BrennanConroy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch @campersau! I missed the ! too.
For the
ChannelClosedException
, we should have a test too right?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't currently any test for the
ChannelClosedException
case, so I have added one which manually throws aChannelClosedException
.Because from looking at the Channels implementation in runtime it looks like these don't throw
ChannelClosedException
from withinWaitToReadAsync
/TryRead
but instead always throw the users exception fromTryComplete(Exception ex)
.Only
ReadAsync
would throw aChannelClosedException
as far as I can tell.https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs#L208-L210
https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs#L167-L169
For reference
AsyncEnumerableAdapters
only usesWaitToReadAsync
/TryRead
:aspnetcore/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs
Line 55 in 3ea008c
Regarding:
Log.FailedInvokingHubMethod
I can change it to use this instead, but maybe a different log might be better to distinguish between those two cases. The case where it would throw immediately vs. the case where it could throw mid reading. (The tests currently throw directly for the first read but it could also happen much later.)
Also
Log.FailedInvokingHubMethod
does not include theinvocationId
which might be useful as this exception might be logged much later.In general the logs are quite inconsistent with the inclusion of the
invocationId
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
ChannelClosedException
was relevant many years ago in the first implementation of the feature: https://github.com/dotnet/aspnetcore/blame/1289636c3afa0e5f297df141359e4ba72dac6e70/src/SignalR/common/Shared/AsyncEnumerableAdapters.cs#L28I'm not against a new log message, it's always helpful to have more specific logs when investigating issues (although you can argue here that the exception stack trace would give you enough information).
I would also be happy with adding the invocation ID to the
FailedInvokingHubMethod
log.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove the
ChannelClosedException
case? I guess there could still be custom Channel implementations which do throw aChannelClosedException
, so maybe no?There are currently three proposed options for logging:
FailedStreaming
as currently proposed in the PR.FailedInvokingHubMethod
.FailedInvokingHubMethod
and add theinvocationId
.I am fine with either of those, just wanted to bring up the discussion.
If we want to go with (3) then there are some other logger messages which currently don't have an
invocationId
so we could add it to them too for consistentcy. Here are all of these:aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 287 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 305 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 349 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 389 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 395 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 451 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 458 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 593 in c9bd468
aspnetcore/src/SignalR/server/Core/src/Internal/DefaultHubDispatcher.cs
Line 603 in c9bd468
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any harm in keeping it.
I'm going to vote for adding a new log, it's more user friendly to see specific logs.
We can look at adding invocation IDs to existing logs in a separate change.