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

fix: adhoc fix session leak #6672

Merged
merged 2 commits into from
Jul 18, 2022
Merged

fix: adhoc fix session leak #6672

merged 2 commits into from
Jul 18, 2022

Conversation

ariesdevil
Copy link
Contributor

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Fix session leak, to detect it, just wrap Arc<Session> to SessionWrapper as following, then check the new and drop are paired:

pub struct SessionWrapper {
    id: usize,
    session: Arc<Session>,
}

impl SessionWrapper {
    pub fn new(s: Arc<Session>) -> Self {
        let backtrace = Backtrace::force_capture();
        let backtrace = format!("{:?}", backtrace);
        let id = GlobalSequence::next();
        println!(
            "session wrapper {} new: {}-{}",
            id,
            Arc::strong_count(&s),
            backtrace
        );
        Self { id, session: s }
    }
}

impl Clone for SessionWrapper {
    fn clone(&self) -> Self {
        Self::new(self.session.clone())
    }
}

impl Drop for SessionWrapper {
    fn drop(&mut self) {
        let backtrace = Backtrace::force_capture();
        let backtrace = format!("{:?}", backtrace);
        println!(
            "session wrapper {} dropped: {}-{}",
            self.id,
            Arc::strong_count(&self.session),
            backtrace
        );
    }
}

impl Deref for SessionWrapper {
    type Target = Arc<Session>;

    fn deref(&self) -> &Self::Target {
        &(self.session)
    }
}

NOTE: this is just an ad-hoc fix, the refactoring of session module will be done related to this issue

Fixes #6560

@vercel
Copy link

vercel bot commented Jul 18, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
databend ✅ Ready (Inspect) Visit Preview Jul 18, 2022 at 3:14PM (UTC)

@mergify mergify bot added the pr-bugfix this PR patches a bug in codebase label Jul 18, 2022
@BohuTANG BohuTANG requested a review from zhang2014 July 18, 2022 14:39
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

I'm not sure about the root cause of this leak, although I partially get involved in the tracing for this problem.

After all, these modification looks good to me:
Always using SessionRef and making the call stack shallow will makes the codebase more clear and easier to understand.

@mergify mergify bot merged commit b0051c5 into databendlabs:main Jul 18, 2022
@ariesdevil ariesdevil deleted the fix-leak branch July 18, 2022 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: session leak
4 participants