Skip to content
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

Follow-up changes for blocking unamed_socket #4099

Closed
wants to merge 8 commits into from

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Dec 20, 2024

Since I left some comments on why the initial throw_unsupported is unreachable, I will just push the follow-up changes from #4072 to here. :)

@rustbot author

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Dec 20, 2024
Copy link
Contributor Author

@tiif tiif Dec 20, 2024

Choose a reason for hiding this comment

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

Currently the diagnostic already shows deadlock on write because we wake up the blocked write thread only if the fd blocked on write is not closed:

Relevant code snippet:

if let Some(peer_fd) = self_anonsocket.peer_fd().upgrade() {
ecx.check_and_update_readiness(&peer_fd)?;
let peer_anonsocket = peer_fd.downcast::<AnonSocket>().unwrap();
// Unblock all threads that are currently blocked on peer_fd's write.
let waiting_threads =
std::mem::take(&mut *peer_anonsocket.blocked_write_tid.borrow_mut());
// FIXME: We can randomize the order of unblocking.
for thread_id in waiting_threads {
ecx.unblock_thread(thread_id, BlockReason::UnnamedSocket)?;
}
};

This is acceptable, but I wanted to try if it is possible to let the diagnostic point to close and tell the user that "this thread never wakes up because of the close here".

EDIT: On other note, this also means that throw_unsupported in anonsocket_write is unreachable.

Copy link
Member

@RalfJung RalfJung Dec 21, 2024

Choose a reason for hiding this comment

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

Currently the diagnostic already shows deadlock on write because we wake up the blocked write thread only if the fd blocked on write is not closed:

There's still an odd throw_unsupported in that logic that we should get rid of. Either it is unreachable and should become an assert, or else you can adjust the test to reach it. (I think it is reachable.)

Improving the diagnostics is nice, but getting rid of that throw_unsupported is the more important part IMO.

Copy link
Contributor Author

@tiif tiif Dec 22, 2024

Choose a reason for hiding this comment

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

After thinking a little bit more, I am inclined to think that the unsupported for unnamed_socket read/write might be both unreachable, so I might remove both. But I will add test(s) to reconfirm it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unsupported in anonsocket_read should be unreachable too because in order to hit that path, it needs to fulfil these conditions:

  1. read must be unblocked (after previously blocked)
  2. The fd blocked (in this test, it is fds[1]) on read is closed.

But after the fd blocked on read (fds[1]) is closed, it is impossible to have a success write on fds[0], so read is never unblocked, condition 1. couldn't be fulfilled.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right... we only wake up a thread if we successfully upgraded the weak ref stored in the peer, and then ofc the weak ref stored in the callback also must still be valid.

@tiif tiif changed the title Handle closing socketpair fd while blocking Follow up fix for blocking unamed_socket Dec 24, 2024
@tiif tiif changed the title Follow up fix for blocking unamed_socket Follow-up changes for blocking unamed_socket Dec 24, 2024
@tiif
Copy link
Contributor Author

tiif commented Dec 27, 2024

These are duplicates of #4112, so I will just close this.

@tiif tiif closed this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: Waiting for the PR author to address review comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants