From 7879d7ecf604316c0a7cc37c8a36dafe9b719545 Mon Sep 17 00:00:00 2001 From: Ronak Jain Date: Sun, 1 Oct 2023 14:06:11 -0700 Subject: [PATCH] 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. --- conn.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 5c8f51d..d78b09f 100644 --- a/conn.go +++ b/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 }