Conversation
dbernero
force-pushed
the
monitor-writer-process
branch
from
September 3, 2026 18:27
7f9e17e to
2364157
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
While the
try/catchstatement inCubDB.transaction/2handles crashes and ordinary exits by a writer process, there are other scenarios where a writer process can die "silently" (e.g. OOM death, killed by an outside process, etc) that will not get caught by the safeguards withintransaction/2.In these cases, a writer process can die while still holding the write lock, preventing the write queue from advancing and leading to deadlock.
Proposed Solution
By having
CubDBmonitor a process as soon as it takes hold of the write lock, we are able to capture process deaths via ahandle_info({:DOWN, ...callback that would not otherwise be caught and handled withintransaction/2, allowing us to advance the write queue and free up the write lock. When the write lock is passed on inadvance_write_queue/1, we can de-monitor the previous writer and monitor the new one (if applicable), ensuring only the active writer is being monitored.Changes
:writer_refto%CubDB.State{}to track the monitor reference for the writer process:writeris assigned, callProcess.monitor/1on that writer and track the refProcess.demonitor/1on the stored ref and monitor the new writer (if there is one)handle_info({:DOWN, ...for the active writer process to catch exits that bypass the safeguards intransaction/2, then advances the write queue