Skip to content

Treat empty multiprocess .db files as empty metrics - #1207

Closed
sankalpsthakur wants to merge 1 commit into
prometheus:masterfrom
sankalpsthakur:cursor/empty-multiprocess-db-a820
Closed

sankalpsthakur wants to merge 1 commit into
prometheus:masterfrom
sankalpsthakur:cursor/empty-multiprocess-db-a820

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Sep 1, 2026 •

Copy link
Copy Markdown

Fixes #1199.

MmapedDict.__init__ creates the backing file before sizing it, so it exists at 0 bytes for a moment. read_all_values_from_file then unpacks a header that is not there, raising struct.error and aborting the whole MultiProcessCollector merge, losing metrics from every other worker as well.

A worker killed in that window leaves the empty file behind for good (it is named after a pid that never returns), so subsequent scrapes fail permanently.

This treats an empty read as a file with nothing recorded yet, the read-side mirror of __init__'s capacity == 0 branch. Non-empty files are unchanged: a file that claims more than it holds still raises, and _read_all_values's corruption check is untouched.

@csmarchbanks

AI assistance: Cursor Agent assisted with the original implementation; Codex assisted with this description.

MmapedDict.__init__ creates the backing file and only truncates it to
_INITIAL_MMAP_SIZE afterwards, so a reader can observe a 0-byte file.
A worker killed in that window leaves the empty file behind permanently,
and read_all_values_from_file then raises struct.error, aborting the
whole MultiProcessCollector merge.

Treat an empty read as a file with nothing recorded yet so collection
continues for other workers. Non-empty corrupt files still fail loudly.

Fixes prometheus#1199

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
Co-authored-by: Sankalp Thakur <sankalpsthakur@users.noreply.github.com>
@sankalpsthakur
sankalpsthakur force-pushed the cursor/empty-multiprocess-db-a820 branch from 149ff4f to 808a45c Compare October 6, 2026 21:25
@sankalpsthakur

Copy link
Copy Markdown
Author

Closing in favour of #1200, which fixes the same empty .db case and was opened first.

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.

MultiProcessCollector fails permanently on an empty metrics file left by a killed worker

1 participant