Skip to content

Conversation

@MihaZupan
Copy link
Member

Fixes #104324

We have two places where we set _readAheadTask:

  • In CheckUsabilityOnScavenge (zero-byte read + fancy synchronization around _readAheadTaskStatus)
  • In PrepareForReuse (simple ReadAsync(readBuffer) right before we start writing a request to an existing connection)

#80214 fixed leaking unobserved exceptions with the former while reintroducing a similar issue with the latter.

In PrepareForReuse, the contract is that the caller will either:

  • Immediately start using the connection and write something to it if PrepareForReuse returned true
  • Immediately dispose the connection if it returned false

In the case where the task completed immediately, we would dispose the connection, but we weren't observing the potential exception from the read-ahead task.

@MihaZupan MihaZupan added this to the 9.0.0 milestone Jul 2, 2024
@MihaZupan MihaZupan requested a review from a team July 2, 2024 22:39
@MihaZupan MihaZupan self-assigned this Jul 2, 2024
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM

}
};

TaskScheduler.UnobservedTaskException += eventHandler;
Copy link
Member

@ManickaP ManickaP Jul 3, 2024

Choose a reason for hiding this comment

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

Unrelated to getting this PR in, but do you think it would be worthwhile to register this handler for all our tests? I'm actually thinking about doing this for S.N.Quic as we did have UnobservedTask issues reported in the past.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we should (probably both Http and Quic).
FWIW the reason the test does filtering on the exception message is because of other unobserved exceptions from Quic 😄
I'll check if I can repro it again.

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've reopened #80111 (comment)

@MihaZupan MihaZupan merged commit 3392893 into dotnet:main Jul 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpClient (using SocketsHttpHandler) may cause unobserved IOException that cannot be caught

3 participants