-
Notifications
You must be signed in to change notification settings - Fork 161
[ISSUE #2378]🔥Implement RocketmqDefaultClient shutdown method🚀 #2379
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
Conversation
WalkthroughThe pull request modifies the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
🔊@mxsm 🚀Thanks for your contribution🎉! 💡CodeRabbit(AI) will review your code first🔥! Note 🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
rocketmq-remoting/src/clients/rocketmq_default_impl.rs (1)
81-81
: Consider making runtime configuration more flexible.The thread count (10) and prefix ("client-thread") are hardcoded. Consider moving these to the
TokioClientConfig
for better configurability.- client_runtime: Some(RocketMQRuntime::new_multi(10, "client-thread")), + client_runtime: Some(RocketMQRuntime::new_multi( + tokio_client_config.runtime_thread_count, + &tokio_client_config.runtime_thread_prefix, + )),
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
rocketmq-remoting/src/clients/rocketmq_default_impl.rs
(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
- GitHub Check: build (windows-latest, nightly)
- GitHub Check: build (windows-latest, stable)
- GitHub Check: build (macos-latest, nightly)
- GitHub Check: build (macos-latest, stable)
- GitHub Check: test
- GitHub Check: build (ubuntu-latest, nightly)
- GitHub Check: build (ubuntu-latest, stable)
- GitHub Check: build
- GitHub Check: auto-approve
🔇 Additional comments (1)
rocketmq-remoting/src/clients/rocketmq_default_impl.rs (1)
60-60
: LGTM! Good choice of type for client_runtime.The change from
Arc<RocketMQRuntime>
toOption<RocketMQRuntime>
is well-thought-out as it:
- Enables proper cleanup during shutdown by allowing ownership transfer
- Makes the runtime's lifecycle clearer by tying it directly to the client
.as_ref() | ||
.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle runtime access safely in invoke methods.
Both invoke_async
and invoke_oneway
use unsafe unwrap()
on the runtime. This could cause panics if the runtime is None.
For invoke_async
, consider:
- match self
- .client_runtime
- .as_ref()
- .unwrap()
+ match self.client_runtime.as_ref()
+ .ok_or_else(|| RemotingError::RemoteError("Runtime not initialized".into()))?
.get_handle()
For invoke_oneway
, consider:
- self.client_runtime
- .as_ref()
- .unwrap()
+ if let Some(runtime) = self.client_runtime.as_ref() {
+ runtime
.get_handle()
.spawn(async move {
match time::timeout(Duration::from_millis(timeout_millis), async move {
let mut request = request;
request.mark_oneway_rpc_ref();
client.send(request).await
})
.await
{
Ok(_) => Ok(()),
Err(err) => Err(RemotingError::RemoteError(err.to_string())),
}
});
+ } else {
+ error!("Failed to send oneway request: runtime not initialized");
+ }
Also applies to: 393-408
self.client_runtime | ||
.as_ref() | ||
.unwrap() | ||
.get_handle() | ||
.spawn(async move { | ||
loop { | ||
client.scan_available_name_srv().await; | ||
time::sleep(Duration::from_millis(connect_timeout_millis)).await; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace unwrap() with proper error handling.
Using unwrap()
on Option<RocketMQRuntime>
could cause panic if the runtime is None. Consider proper error handling:
- self.client_runtime
- .as_ref()
- .unwrap()
- .get_handle()
+ if let Some(runtime) = self.client_runtime.as_ref() {
+ runtime.get_handle()
.spawn(async move {
loop {
client.scan_available_name_srv().await;
time::sleep(Duration::from_millis(connect_timeout_millis)).await;
}
});
+ } else {
+ error!("Failed to start client: runtime not initialized");
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
self.client_runtime | |
.as_ref() | |
.unwrap() | |
.get_handle() | |
.spawn(async move { | |
loop { | |
client.scan_available_name_srv().await; | |
time::sleep(Duration::from_millis(connect_timeout_millis)).await; | |
} | |
}); | |
if let Some(runtime) = self.client_runtime.as_ref() { | |
runtime.get_handle() | |
.spawn(async move { | |
loop { | |
client.scan_available_name_srv().await; | |
time::sleep(Duration::from_millis(connect_timeout_millis)).await; | |
} | |
}); | |
} else { | |
error!("Failed to start client: runtime not initialized"); | |
} |
if let Some(rt) = self.client_runtime.take() { | ||
rt.shutdown(); | ||
} | ||
let connection_tables = self.connection_tables.clone(); | ||
tokio::task::block_in_place(move || { | ||
Handle::current().block_on(async move { | ||
connection_tables.lock().await.clear(); | ||
}); | ||
}); | ||
self.namesrv_addr_list.clear(); | ||
self.available_namesrv_addr_set.clear(); | ||
|
||
info!(">>>>>>>>>>>>>>>RemotingClient shutdown success<<<<<<<<<<<<<<<<<"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve shutdown robustness and error handling.
The shutdown implementation has potential issues:
- Using
block_in_place
inside a runtime can lead to deadlocks if called from a runtime thread - No error handling for connection cleanup failures
Consider this safer implementation:
fn shutdown(&mut self) {
if let Some(rt) = self.client_runtime.take() {
rt.shutdown();
}
- let connection_tables = self.connection_tables.clone();
- tokio::task::block_in_place(move || {
- Handle::current().block_on(async move {
- connection_tables.lock().await.clear();
- });
- });
+ // Create a separate runtime for cleanup to avoid deadlocks
+ let rt = tokio::runtime::Runtime::new()
+ .expect("Failed to create cleanup runtime");
+ if let Err(e) = rt.block_on(async {
+ if let Ok(mut tables) = self.connection_tables.try_lock() {
+ tables.clear();
+ Ok(())
+ } else {
+ Err("Failed to acquire lock for connection cleanup")
+ }
+ }) {
+ error!("Error during connection cleanup: {}", e);
+ }
self.namesrv_addr_list.clear();
self.available_namesrv_addr_set.clear();
info!(">>>>>>>>>>>>>>>RemotingClient shutdown success<<<<<<<<<<<<<<<<<");
}
Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2379 +/- ##
==========================================
- Coverage 28.65% 28.64% -0.01%
==========================================
Files 507 507
Lines 73247 73270 +23
==========================================
Hits 20988 20988
- Misses 52259 52282 +23 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Which Issue(s) This PR Fixes(Closes)
Fixes #2378
Brief Description
How Did You Test This Change?
Summary by CodeRabbit