-
Notifications
You must be signed in to change notification settings - Fork 538
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
[Mono.Android] Fix race condition in AndroidMessageHandler #8753
[Mono.Android] Fix race condition in AndroidMessageHandler #8753
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks for the quick fix. One small comment/suggestion: Is the |
@tipa Yes, we could replace |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@grendello, @simonrozsival: is there any reasonable way to write a unit test for this? |
@jonpryor I haven't come up with a good way to test this. The repro project needs to send several hundreds of requests before it hits the race condition. We could probably use |
@jonpryor I don't think there is such a way. What @simonrozsival proposes would sometimes work and would sometimes fail - another test we learn to ignore. No point IMO. |
Any chance this will be merged and released before .NET 9? :) |
* main: [Mono.Android] Fix race condition in AndroidMessageHandler (#8753) [ci] Fix SDL Sources Analysis for PRs from forks (#8785) [ci] Add 1ESPT override to MSBuild test stages (#8784) [ci] Do not use @self annotation for templates (#8783) [ci] Migrate to the 1ES template (#8747) [Mono.Android] fix trimming warnings, part 2 (#8758) [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (#8777) [tests] fix duplicate sources in `NuGet.config` (#8772) Bump to xamarin/monodroid@e13723e701 (#8771)
* main: [Mono.Android] Fix race condition in AndroidMessageHandler (#8753) [ci] Fix SDL Sources Analysis for PRs from forks (#8785) [ci] Add 1ESPT override to MSBuild test stages (#8784) [ci] Do not use @self annotation for templates (#8783) [ci] Migrate to the 1ES template (#8747) [Mono.Android] fix trimming warnings, part 2 (#8758)
* main: (306 commits) [templates] Remove redundant "template" from display name. (dotnet#8773) Bump to xamarin/Java.Interop/main@a7e09b7 (dotnet#8793) [build] Include MIT license in most NuGet packages (dotnet#8787) Bump to dotnet/installer@893b762b6e 9.0.100-preview.3.24153.2 (dotnet#8782) [docs] update notes about `dotnet-trace` and `dotnet-gcdump` (dotnet#8713) [Mono.Android] Fix race condition in AndroidMessageHandler (dotnet#8753) [ci] Fix SDL Sources Analysis for PRs from forks (dotnet#8785) [ci] Add 1ESPT override to MSBuild test stages (dotnet#8784) [ci] Do not use @self annotation for templates (dotnet#8783) [ci] Migrate to the 1ES template (dotnet#8747) [Mono.Android] fix trimming warnings, part 2 (dotnet#8758) [Xamarin.Android.Build.Tasks] set `%(DefineConstantsOnly)` for older API levels (dotnet#8777) [tests] fix duplicate sources in `NuGet.config` (dotnet#8772) Bump to xamarin/monodroid@e13723e701 (dotnet#8771) Bump to xamarin/xamarin-android-tools/main@37d79c9 (dotnet#8752) Bump to dotnet/installer@d070660282 9.0.100-preview.3.24126.2 (dotnet#8763) Bump to xamarin/java.interop/main@14a9470 (dotnet#8766) $(AndroidPackVersionSuffix)=preview.3; net9 is 34.99.0.preview.3 (dotnet#8765) [Mono.Android] Do not dispose request content stream in AndroidMessageHandler (dotnet#8764) Bump com.android.tools:r8 from 8.2.42 to 8.2.47 (dotnet#8761) ...
Fixes: #8740 There is a race condition in `AndroidMessageHandler` (see #8740 (comment) for more information). The solution is fairly simple: we should determine the decompression strategy only during the setup, when `AutomaticDecompression` is set. We don't need to do any more work during the request. To prevent changing the decompression strategy while there are requests mid-flight, the setter will only accept values until the first request is sent. This is exactly what the `SocketsHttpHandler` does. I didn't want to touch any code unrelated to the race condition in this PR so if we want to prevent other properties from being mutated while HTTP requests are being sent, we should do it in a follow-up PR.
* main: [templates] Remove redundant "template" from display name. (#8773) Bump to xamarin/Java.Interop/main@a7e09b7 (#8793) [build] Include MIT license in most NuGet packages (#8787) Bump to dotnet/installer@893b762b6e 9.0.100-preview.3.24153.2 (#8782) [docs] update notes about `dotnet-trace` and `dotnet-gcdump` (#8713) [Mono.Android] Fix race condition in AndroidMessageHandler (#8753) [ci] Fix SDL Sources Analysis for PRs from forks (#8785) [ci] Add 1ESPT override to MSBuild test stages (#8784) [ci] Do not use @self annotation for templates (#8783) [ci] Migrate to the 1ES template (#8747)
Fixes #8740
There is a race condition in
AndroidMessageHandler
(see #8740 (comment) for more information). The solution is fairly simple: we should determine the decompression strategy only during the setup, whenAutomaticDecompression
is set. We don't need to do any more work during the request.To prevent changing the decompression strategy while there are requests mid-flight, the setter will only accept values until the first request is sent. This is exactly what the
SocketsHttpHandler
does. I didn't want to touch any code unrelated to the race condition in this PR so if we want to prevent other properties from being mutated while HTTP requests are being sent, we should do it in a follow-up PR./cc @grendello