fix(net): break tx loop on non-recoverable errors to prevent busy-loop#606
Open
areporeporepo wants to merge 2 commits intocontainers:mainfrom
Open
fix(net): break tx loop on non-recoverable errors to prevent busy-loop#606areporeporepo wants to merge 2 commits intocontainers:mainfrom
areporeporepo wants to merge 2 commits intocontainers:mainfrom
Conversation
When process_tx() returns a persistent error other than NothingWritten (e.g. Internal or ProcessNotRunning), the loop in process_tx_loop() continues spinning if the guest keeps supplying TX buffers, because tx_has_deferred_frame is false and has_new_entries is true. Break immediately on non-recoverable errors instead of returning false. The worker will be re-entered on the next TX queue kick or backend socket writable event from epoll. Fixes: containers#602 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: anh nguyen <anh.nqqq@icloud.com> Signed-off-by: anh nguyen <29374105+areporeporepo@users.noreply.github.com>
Collaborator
|
/gemini review |
Collaborator
|
@mtjhrc PTAL |
There was a problem hiding this comment.
Code Review
This pull request modifies the virtio net worker to break the TX processing loop upon encountering non-recoverable errors. This change is intended to prevent potential busy-looping scenarios where a guest continues to provide TX buffers despite backend failures. I have no feedback to provide as there were no review comments to evaluate.
mtjhrc
previously approved these changes
Mar 31, 2026
nirs
suggested changes
Apr 5, 2026
| // busy-loop when the guest keeps supplying TX buffers. | ||
| // The worker will be re-entered on the next TX queue kick | ||
| // or backend-writable event. | ||
| break; |
Contributor
There was a problem hiding this comment.
I don't think this is right:
- What would be the value of self.tx_has_deferred_frame after the break? before this change the value is false, which means we don't need to set up a timer.
- Even if the value is false, this is not right since the code is not clear.
- If we break here, we don't call tx_q.queue.enable_notification(&self.mem) which may not be correct. The current code always call tx_q.queue.enable_notification on each iteration.
- There is no busy loop - I think the issue is wrong. The purpose of the worker is to write frames from the guest. If we we cannot write frames we should drop the fame, log an error and continue. In the worst case we will have unrecoverable error that will drop all frames and write lot of logs. There is nothing wrong about this, and it will make the issue easy to debug.
The issue was suggested by Gemini, and I opened it for discussion. I suggest to finish the discussion on the issue before making changes.
Address review feedback: the v1 break skipped enable_notification(), which could cause the guest to stop sending TX queue kicks (especially with EVENT_IDX where enable_notification writes avail_event). Also explicitly reset tx_has_deferred_frame to false for clarity. Fixes: containers#602 Signed-off-by: anh nguyen <29374105+areporeporepo@users.noreply.github.com>
Author
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.
Summary
Fixes #602.
When
process_tx()returns a persistent error other thanNothingWritten(e.g.InternalorProcessNotRunning), the loop inprocess_tx_loop()continues spinning if the guest keeps supplying TX buffers, becausetx_has_deferred_frameisfalseandhas_new_entriesistrue:Fix
Break immediately on non-recoverable errors. The worker will be re-entered on the next:
This is safe because
InternalandProcessNotRunningerrors are non-transient — retrying immediately won't resolve them, but the next epoll cycle gives the system a chance to recover or the guest driver to reset.Change
self.tx_has_deferred_frame = match self.process_tx() { Err(TxError::Backend(WriteError::NothingWritten)) => true, Err(e) => { - false + break; } _ => false, };Testing
cargo clippy --features net -- -D warningspassescargo fmt -- --checkpasses