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:
parent
0d9bfa4d18
commit
7879d7ecf6
7
conn.go
7
conn.go
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue