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

RUST-1443 Ensure monitors close after server is removed from topology #744

Conversation

patrickfreed
Copy link
Contributor

RUST-1443

This PR forward-ports the test added in #733 that verifies that monitors stop executing after their servers are removed from the topology. Running the test yielded a panic in the monitoring task due to a subtraction overflow (heartbeatFrequencyMS < minHeartbeatFrequencyMS), which made me notice we weren't validating heartbeatFrequencyMS when constructing a client via ClientOptions directly. I also fixed that here (RUST-1476).

enforce minHeartbeatFrequencyMS when constructing via client (RUST-1476)
@@ -1325,6 +1325,19 @@ impl ClientOptions {
}
}

if let Some(heartbeat_frequency) = self.heartbeat_freq {
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 validation existed, but it was in the URI parsing stage. I've moved it to ClientOptions::validate to ensure it gets hit even when the options are constructed directly.

#[cfg(not(test))]
let min_frequency = MIN_HEARTBEAT_FREQUENCY;

tokio::select! {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the minimum delay into wait_for_check_request to consolidate the checks for the server closing.

.wait_for_check_request()
.await;
};
tokio::pin!(wait_for_check_request);
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 need the pin here since we're polling the same future repeatedly in a loop.

/// topology.
#[cfg_attr(feature = "tokio-runtime", tokio::test(flavor = "multi_thread"))]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
async fn removed_server_monitor_stops() -> crate::error::Result<()> {
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 test was copied pretty much as-is from #733

@@ -1081,10 +1081,11 @@ pub(crate) struct TopologyCheckRequestReceiver {

impl TopologyCheckRequestReceiver {
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 was a minor change I made to mitigate the case where the value hasn't changed but there are still operations requesting an update. I don't believe this case actually could actually happen with the existing implementation, but I think it's best to make that clear here.

@patrickfreed patrickfreed marked this pull request as ready for review September 15, 2022 18:56
@patrickfreed patrickfreed requested review from a team and abr-egn and removed request for a team September 15, 2022 18:56
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!

/// method will return.
///
/// The `delay` parameter indicates how long this method should wait before listing to requests.
/// It is covered by the provided timeout.
Copy link
Contributor

Choose a reason for hiding this comment

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

does "covered by" mean "counts toward"? like if delay is 1s and timeout is 5s, the method delays for 1s then times out 4s if no requests come in? (I think yes from reading the logic)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, updated the docstring to more be clearer about this.

@patrickfreed patrickfreed merged commit fe018f6 into mongodb:main Sep 27, 2022
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.

4 participants