Skip to content

RUST-1437 Send endSessions on client shutdown #1216

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

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

isabelatkinson
Copy link
Contributor

No description provided.

fn drop(&mut self) {
if !self.inner.shutdown.executed.load(Ordering::SeqCst)
&& !self.inner.dropped.load(Ordering::SeqCst)
&& TrackingArc::strong_count(&self.inner) == 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation would make more sense on ClientInner, which will only drop when all copies of the client are released; however, the operation execution machinery is implemented on Client, which is needed to call run_command. Additionally, something like this doesn't work because drop only takes a mutable reference:

impl Drop for ClientInner {
    fn drop(&mut self) {
        if !self.shutdown.executed.load(Ordering::SeqCst) {
            let client = Client {
                // this can't take ownership
                inner: TrackingArc::new(self),
            }
            ...end sessions
        }
    }
}

@@ -2182,7 +2182,13 @@ impl TestOperation for Close {
Entity::Client(_) => {
let client = entities.get_mut(id).unwrap().as_mut_client();
let closed_client_topology_id = client.topology_id;
client.client = None;
client
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Subtle bug - spawning a future in the client's drop that itself holds onto a client means that the actual ClientInner won't drop until the future finishes running. This is not a big problem, as the types contained in ClientInner don't require any server-side cleanup; however, the Topology emits some events upon close, and if the runtime shuts down before the spawned endSessions future finishes, those events won't be emitted (see here). The fix here is just to run shutdown in this close operation for Client so that no future is spawned when the client is dropped.

This did get me thinking that we could speed up these drop implementations by sending them as unacknowledged writes with moreToCome set, since we're ignoring the results anyway. We would need to add some functionality to the operation/message layer, but I do think this would decrease the likelihood of these spawned tasks not completing before the runtime shuts down.

@isabelatkinson isabelatkinson marked this pull request as ready for review October 8, 2024 01:17
@isabelatkinson isabelatkinson requested a review from abr-egn October 8, 2024 01:17
@isabelatkinson isabelatkinson merged commit e4863f0 into mongodb:main Oct 8, 2024
15 checks passed
@isabelatkinson isabelatkinson deleted the end-sessions branch December 6, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants