Skip to content

Conversation

@tomerdbz
Copy link
Collaborator

@tomerdbz tomerdbz commented Jan 4, 2026

Description

Clear errno before calling wait_for_notification_and_process_element() to avoid checking a stale value from a previous operation.

While current code paths that return -1 do set errno, this defensive approach protects against future changes and follows standard C/Unix practice for errno checking.

What

sockinfo_tcp: clear errno before CQ notification

Why ?

Defensive programming.

How ?

It is optional but for complex PRs please provide information about the design,
architecture, approach, etc.

Change type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Check list

  • Code follows the style de facto guidelines of this project
  • Comments have been inserted in hard to understand places
  • Documentation has been updated (if necessary)
  • Test has been added (if possible)

Clear errno before calling wait_for_notification_and_process_element()
to avoid checking a stale value from a previous operation.

While current code paths that return -1 do set errno, this defensive
approach protects against future changes and follows standard C/Unix
practice for errno checking.

Signed-off-by: Tomer Cabouly <tcabouly@nvidia.com>
@tomerdbz tomerdbz requested a review from galnoam January 4, 2026 07:50
@greptile-apps
Copy link

greptile-apps bot commented Jan 4, 2026

Greptile Summary

This PR adds a defensive programming measure by clearing errno before calling wait_for_notification_and_process_element() in the rx_wait_helper() function. This ensures that only errno values from the current function call are checked, preventing false positives from stale errno values set by previous operations.

Changes:

  • Clear errno to 0 before calling wait_for_notification_and_process_element() at line 4165 in src/vma/sock/sockinfo_tcp.cpp
  • Follows standard Unix/C practice where errno should be cleared before system calls that may set it
  • Protects against future code changes that might unknowingly set errno without signaling an error
  • The error check at line 4167 remains unchanged, only checking errno when the function returns a negative value

Confidence Score: 5/5

  • This PR is safe to merge with no issues identified. The change is a straightforward, defensive coding improvement.
  • The change is minimal, focused, and correct. Clearing errno before a function call that checks errno on error is standard Unix/C practice. The implementation is simple (single line addition), there are no syntax or logic errors, and the change follows good defensive programming practices. The modification is isolated to one location and does not affect any other code paths or APIs.
  • No files require special attention

Important Files Changed

Filename Overview
src/vma/sock/sockinfo_tcp.cpp Single-line change to clear errno before calling wait_for_notification_and_process_element() to prevent checking stale errno values from previous operations. Follows standard Unix/C practice for errno handling. No issues found.

Sequence Diagram

sequenceDiagram
    participant A as epoll_wait
    participant B as Loop
    participant C as ring
    participant D as Error Check
    
    A->>B: events ready
    B->>B: errno = 0
    B->>C: call function
    alt Success
        C-->>B: return value
    end
    B->>D: check errno
    D-->>B: result
Loading

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.

1 participant