Skip to content

fix(backup): retry opening NVMe device on ENXIO race - #568

Open
derekbit wants to merge 3 commits into
longhorn:masterfrom
derekbit:issue-13188
Open

fix(backup): retry opening NVMe device on ENXIO race#568
derekbit wants to merge 3 commits into
longhorn:masterfrom
derekbit:issue-13188

Conversation

@derekbit

Copy link
Copy Markdown
Member

Which issue(s) this PR fixes:

Issue longhorn/longhorn#13188

What this PR does / why we need it:

After the NVMe-oF controller connects, the kernel may not have instantiated the namespace block device yet, causing open() on the device endpoint to return ENXIO. This intermittently fails backup creation right after StartNvmeTCPInitiator returns.

Retry the open up to 10 times with a 500ms fixed delay (5s total) when the error is ENXIO, using retry-go for consistency with the existing retry usage in pkg/spdk/engine.go. Non-ENXIO errors are wrapped in retrygo.Unrecoverable so they fail fast as before.

Special notes for your reviewer:

Additional documentation or context

After the NVMe-oF controller connects, the kernel may not have
instantiated the namespace block device yet, causing open() on the
device endpoint to return ENXIO. This intermittently fails backup
creation right after StartNvmeTCPInitiator returns.

Retry the open up to 10 times with a 500ms fixed delay (5s total)
when the error is ENXIO, using retry-go for consistency with the
existing retry usage in pkg/spdk/engine.go. Non-ENXIO errors are
wrapped in retrygo.Unrecoverable so they fail fast as before.

Longhorn 13188

Signed-off-by: Derek Su <derek.su@suse.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens backup snapshot opening against a known NVMe-oF timing race where the kernel has connected the controller but hasn’t yet created the namespace block device node, causing open() to intermittently fail with ENXIO.

Changes:

  • Add retry-go-based retry logic around opening the NVMe device endpoint in Backup.OpenSnapshot.
  • Retry only on ENXIO and fail fast on any other open error via retrygo.Unrecoverable.
  • Introduce constants for the retry attempt count and delay interval.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/spdk/backup.go Outdated
Comment thread pkg/spdk/backup.go Outdated
Comment thread pkg/spdk/backup.go Outdated
Signed-off-by: Derek Su <derek.su@suse.com>
@derekbit

Copy link
Copy Markdown
Member Author

@mergify backport v1.12.x

@mergify

mergify Bot commented Jun 11, 2026

Copy link
Copy Markdown

backport v1.12.x

🟠 Waiting for conditions to match

Details
  • merged [📌 backport requirement]

@c3y1huang c3y1huang left a comment

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.

I am a bit confused - is this intended to fix longhorn/longhorn#13188?

I looked through the bundle in the issue description, but couldn't find failed to open NVMe device or ENXIO errors. Could you elaborate on how you arrived at this root cause? Is there evidence that links to this code path, or was it reproduced separately?

Also, if this is the correct fix, should we apply the same handling to the other call site as well?

@derekbit

derekbit commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

I am a bit confused - is this intended to fix longhorn/longhorn#13188?

I looked through the bundle in the issue description, but couldn't find failed to open NVMe device or ENXIO errors. Could you elaborate on how you arrived at this root cause? Is there evidence that links to this code path, or was it reproduced separately?

Also, if this is the correct fix, should we apply the same handling to the other call site as well?

Yes. While working on the fix, I encountered an ENXIO error that caused backup failures.
As for the original issue in longhorn/longhorn#13188, I am currently validating my another PR.
In summary, there are many issues that can result in backup failures.

@c3y1huang

Copy link
Copy Markdown
Contributor

Yes. While working on the fix, I encountered an ENXIO error that caused backup failures.
As for the original issue in longhorn/longhorn#13188, I am currently validating my another PR.
In summary, there are many issues that can result in backup failures.

Got it, so this PR is about ENXIO hardening. Should we do the same for the other call site as well?

Longhorn 13188

Signed-off-by: Derek Su <derek.su@suse.com>
@mantissahz
mantissahz requested a review from c3y1huang June 11, 2026 23:53
Comment thread pkg/spdk/util.go
Comment on lines +61 to +62
retry.OnRetry(func(n uint, err error) {
log.Warnf("NVMe device %v not ready (ENXIO), retrying (%d/%d)", endpoint, n+1, openDeviceMaxRetries)

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.

How about dropping the (ENXIO) and letting the errno come from the error itself (.WithError(err))?

@mergify

mergify Bot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request is now in conflict. Could you fix it @derekbit? 🙏

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions Bot added the stale label Aug 8, 2026
@derekbit derekbit removed the stale label Aug 8, 2026
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.

3 participants