Skip to content

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

@propel-code-bot
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

@github-actions
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
rescrv added a commit that referenced this pull request Jun 26, 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
rescrv added a commit that referenced this pull request Jun 27, 2025
## Description of changes

Included changes

- **[ENH] Purge dirty log in background at the end of scheduled
compaction (#4915)**
- **[ENH] Move Log GC to operator (#4919)**
- **[BUG]  Do not leak tokio tasks in the log service. (#4936)**
- **[BUG] Log GC offset should be one above minimum compaction offset
(#4938)**
- **[ENH] Make roll dirty log always converge to coalesce everything.
(#4927)**
- **[BUG] Coalesce when multiple collections return the same info to
compact (#4946)**
- **[BUG]  Enrich from the manifest if a cursor doesn't exist. (#4947)**
- **[ENH] If the dirty log fails with LogContentionDurable, do not fail
the operation. (#4953)**
- **[ENH]  Warn, not error, if dirty log has no cursor. (#4952)**
- **[ENH]  Cancellation safety for append_batch. (#4959)**

## Test plan

CI

## Documentation Changes

N/A

---------

Co-authored-by: Macronova <[email protected]>
Inventrohyder pushed a commit to Inventrohyder/chroma that referenced this pull request Aug 5, 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
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.

3 participants