Skip to content

Commit

Permalink
Flush: fix error leak when flushing multiple messages
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 Sep 12, 2023
1 parent d27cc52 commit bb717cf
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 @@ -230,16 +230,21 @@ 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 msg.Header.Flags&netlink.Acknowledge == 0 {
continue // message did not request an acknowledgement
}
if _, err := conn.Receive(); 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 bb717cf

Please sign in to comment.