Skip to content

RUST-1047 Ensure TopologyClosedEvent is the last SDAM event emitted #485

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

Conversation

patrickfreed
Copy link
Contributor

RUST-1047

This PR fixes a race between server monitoring and topology closing that would occasionally result in heartbeat events being emitted after the final TopologyClosedEvent.

@@ -169,21 +173,6 @@ impl Topology {

pub(crate) fn close(&self) {
self.common.is_alive.store(false, Ordering::SeqCst);
if let Some(ref handler) = self.common.options.sdam_event_handler {
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 logic was moved to the drop of TopologyState, so it's guaranteed to come after any work the monitor does because the monitor holds onto a strong reference to the topology (Topology) while it's performing a heartbeat.

src/is_master.rs Outdated
/// Execute an isMaster command, emiting events if a reference to the topology and a handler are provided.
///
/// A strong reference to the topology is used here to ensure it is still in scope and has not yet emitted a
/// `TopologyClosedEvent`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to pass the Topology down through this similar to how we were doing it with WeakTopology before. It's a bit hairy right now, but I imagine this will all become a lot more straightforward and cleaned up once we do the topology refactor.

@patrickfreed patrickfreed marked this pull request as ready for review October 11, 2021 17:34
src/is_master.rs Outdated
cmap::{Command, Connection},
error::Result,
event::sdam::{
}, cmap::{Command, Connection}, error::Result, event::sdam::{
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: did rustfmt change logic for use clauses? The grouping here looks odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Based on the way check-rustfmt.sh was written, files in src but not in a subdirectory (like is_master.rs) weren't getting linted for formatting. I've reformated this file and also updated check-rustfmt.sh to account for these files too.

Copy link
Contributor

@abr-egn abr-egn left a comment

Choose a reason for hiding this comment

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

LGTM!

@patrickfreed patrickfreed merged commit 6c1f687 into mongodb:master Oct 12, 2021
patrickfreed added a commit to patrickfreed/mongo-rust-driver that referenced this pull request Oct 12, 2021
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.

3 participants