From ecea5b9258c8c922aa639480fb9c2550b7079f03 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Wed, 13 Sep 2023 19:58:01 +0200 Subject: [PATCH] Fix AwaitableSocketAsyncEventArgs reorderings on weaker memory models (#50624) * Fix AwaitableSocketAsyncEventArgs reorderings on weaker memory models * add comment --- .../src/Internal/SocketAwaitableEventArgs.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketAwaitableEventArgs.cs b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketAwaitableEventArgs.cs index 86f66c4b94f3..01daad023ba6 100644 --- a/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketAwaitableEventArgs.cs +++ b/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketAwaitableEventArgs.cs @@ -18,7 +18,11 @@ internal class SocketAwaitableEventArgs : SocketAsyncEventArgs, IValueTaskSource private readonly PipeScheduler _ioScheduler; - private Action? _continuation; + // There are places where we read the _continuation field and then read some other state which we assume to be consistent + // with the value we read in _continuation. Without a fence, those secondary reads could be reordered with respect to the first. + // https://github.com/dotnet/runtime/pull/84432 + // https://github.com/dotnet/aspnetcore/issues/50623 + private volatile Action? _continuation; public SocketAwaitableEventArgs(PipeScheduler ioScheduler) : base(unsafeSuppressExecutionContextFlow: true)