Skip to content

Commit

Permalink
proof: ensure that recv ACK stream is closed correctly
Browse files Browse the repository at this point in the history
This commit modifies the `HashMailBox.RecvAck` method to ensure that the
receive ACK gRPC stream is closed successfully.
  • Loading branch information
ffranr committed Aug 27, 2024
1 parent 465a567 commit f815866
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion proof/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,17 @@ func (h *HashMailBox) RecvAck(ctx context.Context, sid streamID) error {
return fmt.Errorf("unable to create read stream: %w", err)
}

// Ensure the read stream is closed before returning.
defer func() {
log.Debugf("Closing hashmail read stream (sid=%x)", sid[:])

err := readStream.CloseSend()
if err != nil {
log.Errorf("Unable to close hashmail read stream: %v",
err)
}
}()

log.Debugf("Exec stream Recv for receiver ACK (sid=%x)", sid[:])
msg, err := readStream.Recv()
if err != nil {
Expand All @@ -447,10 +458,11 @@ func (h *HashMailBox) RecvAck(ctx context.Context, sid streamID) error {
}

if bytes.Equal(msg.Msg, ackMsg) {
log.Debugf("Received ACK from sender (sid=%x)", sid[:])
return nil
}

return fmt.Errorf("expected ack, got %x", msg.Msg)
return fmt.Errorf("expected ACK from hashmail service, got %x", msg.Msg)
}

// CleanUp attempts to tear down the mailbox as specified by the passed sid.
Expand Down

0 comments on commit f815866

Please sign in to comment.