Skip to content

Prevent the disk blob cache from deadlocking during save - #507

Open
Peaks2000 wants to merge 1 commit into
ViaVersionAddons:mainfrom
Peaks2000:fix/blob-cache-save-deadlock
Open

Peaks2000 wants to merge 1 commit into
ViaVersionAddons:mainfrom
Peaks2000:fix/blob-cache-save-deadlock

Conversation

@Peaks2000

Copy link
Copy Markdown

Problem

BlobDb.save() holds the database monitor while waiting for pendingWrites to empty. The background writer needs that same monitor to flush the queue, so the disk cache shutdown hook can hang. save() can also return with queued entries if the index has not been marked dirty yet.

This affects ViaFabricPlus Bedrock's bundled ViaBedrock, which uses the disk cache by default.

Fix

Flush queued entries in save() before deciding whether to persist the index. The background writer uses the same flush logic and releases the monitor between entries. A write error leaves the failing entry queued for retry.

Adapted from the ViaBedrock fork fix.

Validation

  • Gradle build and Checkstyle passed on Java 25 with the addon-related ports applied.
  • A local regression probe verified that save returns with pending writes, both a previously dirty index and a new database reopen with the queued bytes, and an I/O failure leaves the entry available for retry.

@AlexProgrammerDE AlexProgrammerDE left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note

🤖 Claude Opus 5.5 responding on behalf of AlexProgrammerDE

The deadlock is real: save() held the monitor in waitForWrites() while the writer thread needed it for putNow(). Flushing inside save() fixes that and the skipped save when the index was not dirty yet. queuePut takes the same monitor, so the get, write and remove sequence in flushPendingWrites cannot race with it.

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