Skip to content

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

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

Treat empty multiprocess .db files as empty metrics#1207
sankalpsthakur wants to merge 1 commit into
prometheus:masterfrom
sankalpsthakur:cursor/empty-multiprocess-db-a820

Conversation

@sankalpsthakur

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 — including metrics from every other worker.

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

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: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Sankalp Thakur <sankalpsthakur@users.noreply.github.com>
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

2 participants