Skip to content

fix: handle 'delayed' state in sync_completed parsing - #786

Open
mehrdadbn9 wants to merge 1 commit into
prometheus:masterfrom
mehrdadbn9:fix/sync-completed-delayed
Open

fix: handle 'delayed' state in sync_completed parsing#786
mehrdadbn9 wants to merge 1 commit into
prometheus:masterfrom
mehrdadbn9:fix/sync-completed-delayed

Conversation

@mehrdadbn9

Copy link
Copy Markdown

Summary

  • Handle delayed as a special value in sync_completed parsing (similar to none)
  • When multiple MD RAID arrays share physical devices and a check/resync is triggered for more than one, the kernel delays the action on all but one device
  • In this case, sync_completed contains delayed instead of none or N / M

Problem

The current code fails when sync_completed contains delayed:

error parsing mdraids: expected integer

Solution

Add delayed to the list of special values that should not be parsed as integers.

Testing

  • Tested with manual test cases: none, delayed, 123 / 456, invalid
  • All cases handled correctly

Fixes #770
Related: prometheus/node_exporter#3500

mehrdadbn9 added a commit to mehrdadbn9/procfs that referenced this pull request Feb 25, 2026
- Add TestMdraidDelayedSyncCompleted to verify delayed state handling
- Include complete test data with delayed sync_completed value
- Test verifies SyncCompleted=0, SyncAction='resync', and all component states

Fixes prometheus#786
@SuperQ
SuperQ requested a review from dswarbrick February 28, 2026 15:18

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs a DCO sign-off. You can use git commit -s --amend to add it.

Comment thread sysfs/mdraid.go
}

if val, err := util.SysReadFile(filepath.Join(path, "sync_completed")); err == nil {
if val != "none" {

@dswarbrick dswarbrick Apr 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even though "none" and "delayed" are currently the only two special cases (as of kernel v6.19.10), I wonder if this would be more robust if we performed a regex match, or flipped the logic around the fmt.Sscanf so that it would handle future special cases that don't match the %d / %d format.

@mehrdadbn9
mehrdadbn9 force-pushed the fix/sync-completed-delayed branch from 427ead0 to b53b9c2 Compare August 14, 2026 20:54
mehrdadbn9 added a commit to mehrdadbn9/procfs that referenced this pull request Aug 14, 2026
- Add TestMdraidDelayedSyncCompleted to verify delayed state handling
- Include complete test data with delayed sync_completed value
- Test verifies SyncCompleted=0, SyncAction='resync', and all component states

Fixes prometheus#786

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
mehrdadbn9 pushed a commit to mehrdadbn9/procfs that referenced this pull request Aug 14, 2026
Add 'delayed' to the special values in sync_completed parsing (similar
to 'none'). When multiple MD RAID arrays share physical devices and a
check/resync is triggered for more than one, the kernel delays the
action on all but one device, so sync_completed contains 'delayed'
instead of 'none' or 'N / M', which previously caused
'error parsing mdraids: expected integer'.

Fixes prometheus#786

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
Add 'delayed' to the special values in sync_completed parsing (similar
to 'none'). When multiple MD RAID arrays share physical devices and a
check/resync is triggered for more than one, the kernel delays the
action on all but one device, so sync_completed contains 'delayed'
instead of 'none' or 'N / M', which previously caused
'error parsing mdraids: expected integer'.

Adds a regression fixture (testdata/fixtures/sys/issue770) and
TestMdraidDelayedSyncCompleted covering the delayed state.

Fixes prometheus#786

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
@mehrdadbn9
mehrdadbn9 force-pushed the fix/sync-completed-delayed branch from b53b9c2 to 68b0e29 Compare August 14, 2026 20:55
@mehrdadbn9

Copy link
Copy Markdown
Author

@SuperQ DCO sign-off added (single squashed commit, Signed-off-by present and DCO check now passes).

While reworking this I also found and fixed a real defect in the PR itself: the regression test referenced testdata/fixtures/sys/issue770 but the fixture had been committed at the wrong path (testdata/issue770/...), so TestMdraidDelayedSyncCompleted could never pass. I moved the fixture into the standard testdata/fixtures.ttar archive (the procfs fixture mechanism) and regenerated it. TestMdraidDelayedSyncCompleted and TestMdraidStats now pass.

Force-pushed 68b0e29. The change handles delayed in sync_completed (mirrors none) so multi-array MD RAID resync no longer errors with expected integer. Fixes #770.

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.

sysfs.Mdraids() fails if any MD raid array has a delayed check or resync

3 participants