[S] Change in dart/sdk[main]: [io/socket] Make Socket::fd_ atomic since it can get updated from mul...

2 views
Skip to first unread message

Alexander Aprelev (Gerrit)

unread,
Sep 25, 2025, 5:52:34 PM (4 days ago) Sep 25
to Alexander Aprelev, Tess Strickland, Commit Queue, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Tess Strickland

Alexander Aprelev voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Tess Strickland
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 3
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-Attention: Tess Strickland <sstr...@google.com>
Gerrit-Comment-Date: Thu, 25 Sep 2025 21:52:30 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Tess Strickland (Gerrit)

unread,
Sep 26, 2025, 6:45:59 AM (3 days ago) Sep 26
to Alexander Aprelev, Commit Queue, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev

Tess Strickland voted and added 1 comment

Votes added by Tess Strickland

Code-Review+1

1 comment

Patchset-level comments
File-level comment, Patchset 3 (Latest):
Tess Strickland . resolved

Thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 3
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-Attention: Alexander Aprelev <a...@google.com>
Gerrit-Comment-Date: Fri, 26 Sep 2025 10:45:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Sep 26, 2025, 10:01:09 AM (3 days ago) Sep 26
to Alexander Aprelev, Tess Strickland, Commit Queue, rev...@dartlang.org, vm-...@dartlang.org

Alexander Aprelev voted and added 1 comment

Votes added by Alexander Aprelev

Commit-Queue+2

1 comment

Patchset-level comments
Alexander Aprelev . resolved

thank you Tess!

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 3
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-Comment-Date: Fri, 26 Sep 2025 14:01:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Commit Queue (Gerrit)

unread,
Sep 26, 2025, 10:01:29 AM (3 days ago) Sep 26
to Alexander Aprelev, Tess Strickland, rev...@dartlang.org, vm-...@dartlang.org

Commit Queue submitted the change

Change information

Commit message:
[io/socket] Make Socket::fd_ atomic since it can get updated from multiple threads.

Follow-up to https://dart.googlesource.com/sdk/+/ba7aaa929f579aaa55a2fc09a098f81df6b27804, sink the "is fd closed" check to avoid multiple reads.

Fixes https://github.com/dart-lang/sdk/issues/61582
TEST=ci
Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Reviewed-by: Tess Strickland <sstr...@google.com>
Commit-Queue: Alexander Aprelev <a...@google.com>
Files:
  • M runtime/bin/socket.cc
  • M runtime/bin/socket.h
  • M runtime/bin/socket_base_win.cc
  • M runtime/bin/socket_win.cc
Change size: S
Delta: 4 files changed, 10 insertions(+), 9 deletions(-)
Branch: refs/heads/main
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Tess Strickland
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 4
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
open
diffy
satisfied_requirement

Slava Egorov (Gerrit)

unread,
Sep 26, 2025, 3:50:28 PM (3 days ago) Sep 26
to Alexander Aprelev, Commit Queue, Tess Strickland, rev...@dartlang.org, vm-...@dartlang.org

Slava Egorov added 1 comment

Patchset-level comments
File-level comment, Patchset 4 (Latest):
Slava Egorov . resolved

I am sorry, maybe I am missing something. How does this fix the race itself?

TSAN reported that Builtin_Socket_GetType races with closure of the socket happening on the event handler thread. That's great finding. What does this CL do to *fix* the underlying race? We are still racing - we might get stale FD just as event handler is closing/deleting that thing. Is it not the case?

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 4
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-CC: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Fri, 26 Sep 2025 19:50:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Sep 26, 2025, 4:03:22 PM (3 days ago) Sep 26
to Alexander Aprelev, Commit Queue, Slava Egorov, Tess Strickland, rev...@dartlang.org, vm-...@dartlang.org

Alexander Aprelev added 1 comment

Patchset-level comments
Slava Egorov . resolved

I am sorry, maybe I am missing something. How does this fix the race itself?

TSAN reported that Builtin_Socket_GetType races with closure of the socket happening on the event handler thread. That's great finding. What does this CL do to *fix* the underlying race? We are still racing - we might get stale FD just as event handler is closing/deleting that thing. Is it not the case?

Alexander Aprelev

The goal of this cl was to fix the crash that happens in case of this race - ensure we don't try to dereference closed fd. It seems that the race itself is unavoidable.

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 4
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-CC: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Fri, 26 Sep 2025 20:03:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Sep 26, 2025, 4:24:38 PM (3 days ago) Sep 26
to Alexander Aprelev, Commit Queue, Tess Strickland, rev...@dartlang.org, vm-...@dartlang.org

Slava Egorov added 1 comment

Patchset-level comments
Slava Egorov . resolved

I am sorry, maybe I am missing something. How does this fix the race itself?

TSAN reported that Builtin_Socket_GetType races with closure of the socket happening on the event handler thread. That's great finding. What does this CL do to *fix* the underlying race? We are still racing - we might get stale FD just as event handler is closing/deleting that thing. Is it not the case?

Alexander Aprelev

The goal of this cl was to fix the crash that happens in case of this race - ensure we don't try to dereference closed fd. It seems that the race itself is unavoidable.

Slava Egorov

So how does this CL ensure that? The situation is equivalent to

```
Thread 1:
foo = bar.x
use(foo->baz)

Thread 2:
delete bar.x
bar.x = deleted_marker // -1
```

The code became:

```
Thread 1:
foo = bar.x
if (foo == deleted_marker) return;
use(foo->baz)

Thread 2:
delete bar.x
bar.x = nullptr
```

This `if` by no means avoids either the race or a crash because the following sequence if possible:

```
T1: foo = bar.x // != marker
T2: delete bar.x
T1: if (foo == deleted_marker) return; // false
T1: foo->baz // crash
```

It seems that the race itself is unavoidable

I am not sure. `NativeSocket` has `isClosing` which is set when we dispatch `closeCommand` to the eventhandler. So I would imagine that checking that in `_nativeSocketType` before calling `_getSocketType` should help.

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 4
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-CC: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Fri, 26 Sep 2025 20:24:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Alexander Aprelev <a...@google.com>
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Sep 26, 2025, 4:54:59 PM (3 days ago) Sep 26
to Alexander Aprelev, Commit Queue, Slava Egorov, Tess Strickland, rev...@dartlang.org, vm-...@dartlang.org

Alexander Aprelev added 1 comment

Patchset-level comments
Alexander Aprelev

So I would imagine that checking that in _nativeSocketType before calling _getSocketType should help.

Thank you, I think you are right. Somehow I thought that there is no way to guarantee ordering between close message handling done by eventhandler thread and isolate mutator thread accessing socket. https://dart-review.googlesource.com/c/sdk/+/451822

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Gerrit-Change-Number: 451600
Gerrit-PatchSet: 4
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Tess Strickland <sstr...@google.com>
Gerrit-CC: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Fri, 26 Sep 2025 20:54:56 +0000
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages