Skip to content

fix: writer starvation in DatasetConsistencyWrapper#6323

Open
emilk wants to merge 1 commit intolance-format:mainfrom
rerun-io:emilk/fix-write-starvation
Open

fix: writer starvation in DatasetConsistencyWrapper#6323
emilk wants to merge 1 commit intolance-format:mainfrom
rerun-io:emilk/fix-write-starvation

Conversation

@emilk
Copy link
Copy Markdown

@emilk emilk commented Mar 28, 2026

Summary

  • Fix writer starvation caused by get_mut() acquiring a read lock (via reload()) before requesting the write lock, which prevented tokio's RwLock write-fairness from protecting the writer
  • get_mut() now acquires the write lock first, then reloads under that lock via a new reload_under_write_lock() helper

Problem

DatasetConsistencyWrapper uses a tokio::sync::RwLock, which is write-fair: once a writer is waiting, no new readers are admitted. However, get_mut() called reload() before requesting the write lock, and reload() itself acquires a read lock to check the current version. This meant the writer was competing as a reader during the reload phase, so tokio never saw a pending writer and its fairness guarantee never kicked in.

Under high read concurrency, writers could starve indefinitely; each time the writer's reload() read lock was released, new readers would slip in before the subsequent .write().await could be served.

Fix

Restructure get_mut() to acquire the write lock first, then perform the reload under that exclusive lock. This ensures tokio's write-fairness blocks new readers as soon as a writer calls get_mut(). The read path (get()) is unchanged and still uses the optimistic read-lock-first strategy.

@github-actions
Copy link
Copy Markdown
Contributor

ACTION NEEDED
Lance follows the Conventional Commits specification for release automation.

The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification.

For details on the error please inspect the "PR Title Check" action.

@emilk emilk changed the title Fix writer starvation in DatasetConsistencyWrapper fix: writer starvation in DatasetConsistencyWrapper Mar 28, 2026
@github-actions github-actions bot added the bug Something isn't working label Mar 28, 2026
@wjones127 wjones127 self-assigned this Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants