Flush: fix error leak when flushing multiple messages (#239)

When you flush multiple messages/ops on a connection, and if flush fails
to apply, the netlink connection returns errors per command. Since we
are returning on noticing the first error, the rest of the errors are
buffered and leaks into the result of next flush.

This pull request invokes `conn.Receive()` * number of messages to drain
any buffered errors in the connection.
This commit is contained in:
Ronak Jain 2023-10-01 14:06:11 -07:00 committed by GitHub
parent 0d9bfa4d18
commit 7879d7ecf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -249,13 +249,18 @@ func (cc *Conn) Flush() error {
return fmt.Errorf("SendMessages: %w", err)
}
var errs error
// Fetch the requested acknowledgement for each message we sent.
for _, msg := range cc.messages {
if _, err := receiveAckAware(conn, msg.Header.Flags); err != nil {
return fmt.Errorf("conn.Receive: %w", err)
errs = errors.Join(errs, err)
}
}
if errs != nil {
return fmt.Errorf("conn.Receive: %w", errs)
}
return nil
}