Skip to content

[BUG] Do not leak tokio tasks in the log service. #4936

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
merged 1 commit into from
Jun 25, 2025

Conversation

rescrv
Copy link
Contributor

@rescrv rescrv commented Jun 25, 2025

Description of changes

The background tasks of wal3 were leaked because the log service was not
calling shutdown when dropping a log. This PR corrects that.

Test plan

Local benchmark. Will upload graph to GitHub PR.

Documentation Changes

N/A

Copy link
Contributor

propel-code-bot bot commented Jun 25, 2025

This PR ensures that background Tokio tasks spawned by the wal3 log service are properly terminated by implementing a Drop handler for LogWriter, which now calls the shutdown method on the inner writer upon dropping. This prevents resource leakage when a log is closed or dropped.

This summary was automatically generated by @propel-code-bot

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Comment on lines +382 to +387
let mut inner = self.inner.lock().unwrap();
if let Some(writer) = inner.writer.as_mut() {
Copy link
Contributor

Choose a reason for hiding this comment

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

[CompanyBestPractice]

Consider using parking_lot::Mutex instead of std::sync::Mutex in the LogWriter::drop implementation. Our company guideline states that parking_lot provides faster, more efficient implementations of synchronization primitives.

Suggested change
let mut inner = self.inner.lock().unwrap();
if let Some(writer) = inner.writer.as_mut() {
let mut inner = self.inner.lock();
if let Some(writer) = inner.writer.as_mut() {
writer.shutdown();
}

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

@rescrv
Copy link
Contributor Author

rescrv commented Jun 25, 2025

leak
In this graph we plot the number of tokio tasks over time. Then we write to 10k collections. Notice that the tasks do not level off in the before, but do level off in the after.

@rescrv rescrv force-pushed the rescrv/no-leak-tokio-tasks branch from 377296f to b69b94d Compare June 25, 2025 04:19
@rescrv rescrv changed the base branch from rescrv/roll-dirty-log to main June 25, 2025 04:19
@rescrv rescrv force-pushed the rescrv/no-leak-tokio-tasks branch from e7731ee to 3e0c82d Compare June 25, 2025 13:14
The background tasks of wal3 were leaked because the log service was not
calling shutdown when dropping a log.  This PR corrects that.
@rescrv rescrv force-pushed the rescrv/no-leak-tokio-tasks branch 2 times, most recently from 5b1283e to ae3ed46 Compare June 25, 2025 17:23
@rescrv rescrv merged commit cad244f into main Jun 25, 2025
57 checks passed
@rescrv rescrv deleted the rescrv/no-leak-tokio-tasks branch June 25, 2025 17:54
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.

2 participants