-
Notifications
You must be signed in to change notification settings - Fork 753
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
bugfix: Global MetaGrpcClient cause dispatch drop error #4361
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/databend/databend/7c3JkV9riAtfm8dyWkEgJjSYZiWq [Deployment for 157ff97 canceled] |
Thanks for the contribution! Please review the labels and make any necessary changes. |
GLOBAL_META_EMBEDDED not inited https://github.com/youngsofun/databend/commits/zyj_dev test passed after it is inited |
block_on inside async block may lead to dead lock, is this the case here? seanmonstar/reqwest#1215 (comment) cc @zhang2014 is this the reason for https://github.com/datafuselabs/databend/pull/4317/files? authenticate() is called in an async fn init() |
Previously We using session_mgr to create KVApi that only one tmp meta_store will created. Now we change to create KVApi by session, so each session will create it's own tmp meta_store When using global init here it can be passed if we just run this test only, but if we run with
|
try to run globalinit only once in tests? including 1.utils like once staic |
We should avoid using global init in unit tests, global init is just used when query node init and no meta node is configured in the config file. Let's find a way solve it. |
@@ -201,7 +201,8 @@ impl SessionManager { | |||
&self.conf.query.cluster_id, | |||
); | |||
|
|||
self.active_sessions.write().remove(session_id); | |||
let mut sessions = futures::executor::block_on(self.active_sessions.write()); |
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.
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.
This function is eventually called by drop function that impl Drop trait, async drop still in rust roadmap...
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.
Is it possible to make active_sessions
an std::sync::Mutex
?
Then the await
can be get rid of.
But using a sync-mode mutex introduces some retry-loops when inserting items into it.
Because it can not be held across an 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.
i guess std::sync::Mutex is ok in this case, but we should be careful NOT to introduce any async/await point inside the mutex guard.
- sync mutex lock
- await yield out to another coroutine
- another coroutine tries to acquire the lock, and dead lock
however, it's a good practise to not do any blocking operations (includes logging) inside a mutex guard
got it. so we need:
|
@ariesdevil wrt http handler, I prefer to retain global auth_mgr/user_mgr. when not related to diff runtimes, it is safe and efficient to have a global conn pool, we can add some comment avoid miss using it.
I think of 2 ways
|
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.
It looks good to me.
But I'm not familiar with the underlying logic around session
.
So let experts approve.
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Bugfix: Global MetaGrpcClient cause dispatch drop error.
MetaGrpcClient
fromSessionManager
toSession
to avoid cross-runtime client clone.NOTE
The current implementation leaves two issues
Drop
trait that impl by SessionRef usingblock_on
to call async fn.Changelog
Related Issues
Fixes #4347
Test Plan
Unit Tests
Stateless Tests