Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTON-2843: [Go] Fix segfault with acknowledging a message on closed receiver #432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions go/pkg/electron/electron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,18 @@ func TestHeartbeat(t *testing.T) {
t.Error("expected server side time-out or connection abort error")
}
}

func TestReceiverCloseBeforeAcknowledge(t *testing.T) {
p := newPipe(t, nil, nil)
defer func() { p.close() }()
r, s := p.receiver(Source("foo"))
go func() {
out := s.SendSync(amqp.NewMessageWith(0))
_ = test.ErrorIf(t, test.Differ(Closed, out.Error))
}()
rm, err := r.Receive()
test.FatalIf(t, err)
r.Close(nil)
<-r.Done()
_ = test.ErrorIf(t, test.Differ(Closed, rm.Accept()))
}
16 changes: 12 additions & 4 deletions go/pkg/electron/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
)

// Receiver is a Link that receives messages.
//
type Receiver interface {
Endpoint
LinkSettings
Expand Down Expand Up @@ -201,10 +200,19 @@ type ReceivedMessage struct {

// Acknowledge a ReceivedMessage with the given delivery status.
func (rm *ReceivedMessage) acknowledge(status uint64) error {
return rm.receiver.(*receiver).engine().Inject(func() {
// Deliveries are valid as long as the connection is, unless settled.
rm.pDelivery.SettleAs(uint64(status))
receiverError := make(chan error)
err := rm.receiver.(*receiver).engine().Inject(func() {
// Deliveries are valid as long as the receiver is, unless settled.
err := rm.receiver.Error()
receiverError <- err
if err == nil {
rm.pDelivery.SettleAs(status)
}
})
if err != nil {
return err
}
return <-receiverError
}

// Accept tells the sender that we take responsibility for processing the message.
Expand Down
Loading