Skip to content

Commit

Permalink
Flush: fix error leak when flushing multiple messages (#239)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jronak committed Oct 1, 2023
1 parent 0d9bfa4 commit 7879d7e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7879d7e

Please sign in to comment.