Skip to content

Commit

Permalink
Merge remote-tracking branch 'rabbitmqgh-69/reader_go_routine_hang_te…
Browse files Browse the repository at this point in the history
…stcase' into reader_routine_leak
  • Loading branch information
lukebakken committed Apr 14, 2022
2 parents 12955c2 + bfa7b47 commit 3a68d06
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"sync"
"testing"
"time"

"go.uber.org/goleak"
)

func TestRequiredServerLocale(t *testing.T) {
Expand Down Expand Up @@ -210,3 +212,32 @@ func TestChannelIsClosed(t *testing.T) {
t.Fatal("channel expected to be marked as closed")
}
}

// TestReaderGoRoutineTerminatesWhenMsgIsProcessedDuringClose tests the issue
// described in https://github.com/rabbitmq/amqp091-go/issues/69.
func TestReaderGoRoutineTerminatesWhenMsgIsProcessedDuringClose(t *testing.T) {
const routines = 10
defer goleak.VerifyNone(t)
c := integrationConnection(t, t.Name())

var wg sync.WaitGroup
startSigCh := make(chan interface{})

for i := 0; i < routines; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()

<-startSigCh

err := c.Close()
if err != nil {
t.Logf("close failed in routine %d: %s", id, err.Error())
}
}(i)
}
close(startSigCh)

t.Log("waiting for go-routines to terminate")
wg.Wait()
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/rabbitmq/amqp091-go

go 1.16

require go.uber.org/goleak v1.1.12

0 comments on commit 3a68d06

Please sign in to comment.