socket: handle ErrDumpInterrupted in SocketGet

SocketGet uses NLM_F_DUMP and already documents that it may return
ErrDumpInterrupted, but the implementation treats it as a hard failure,
discarding any partial results. When the dump is interrupted but a
matching socket was found in the partial results, the function should
still return it alongside the ErrDumpInterrupted error.

When no messages are returned and the error is ErrDumpInterrupted,
propagate the original error instead of the generic "no message nor
error from netlink" message, giving callers a proper signal to retry.

Follow-up to 084abd93d3 ("Add support for NLM_F_DUMP_INTR")

Signed-off-by: Ihar Hrachyshka <ihrachyshka@nvidia.com>
Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ihar Hrachyshka
2026-02-25 10:44:21 -05:00
committed by Alessandro Boch
parent 6522a30a56
commit ddba687f44
+7 -4
View File
@@ -216,11 +216,14 @@ func (h *Handle) SocketGet(local, remote net.Addr) (*Socket, error) {
},
})
msgs, err := req.Execute(unix.NETLINK_INET_DIAG, nl.SOCK_DIAG_BY_FAMILY)
if err != nil {
return nil, err
msgs, executeErr := req.Execute(unix.NETLINK_INET_DIAG, nl.SOCK_DIAG_BY_FAMILY)
if executeErr != nil && !errors.Is(executeErr, ErrDumpInterrupted) {
return nil, executeErr
}
if len(msgs) == 0 {
if executeErr != nil {
return nil, executeErr
}
return nil, errors.New("no message nor error from netlink")
}
if len(msgs) > 2 {
@@ -231,7 +234,7 @@ func (h *Handle) SocketGet(local, remote net.Addr) (*Socket, error) {
if err := sock.deserialize(msgs[0]); err != nil {
return nil, err
}
return sock, nil
return sock, executeErr
}
// SocketGet returns the Socket identified by its local and remote addresses.