diff --git a/Makefile b/Makefile index 47e882f..7342731 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,8 @@ fmt: ## Run go fmt against code go fmt ./... .PHONY: tests -tests: ## Run all tests and requires a running rabbitmq-server - go test -cpu 1,2 -race -v -tags integration +tests: ## Run all tests and requires a running rabbitmq-server. Use GO_TEST_FLAGS to add extra flags to go test + go test -race -v -tags integration $(GO_TEST_FLAGS) .PHONY: check check: diff --git a/connection.go b/connection.go index e01d835..23f1832 100644 --- a/connection.go +++ b/connection.go @@ -912,6 +912,9 @@ func (c *Connection) openTune(config Config, auth Authentication) error { return ErrCredentials } + // Edge case that may race with c.shutdown() + // https://github.com/rabbitmq/amqp091-go/issues/170 + c.m.Lock() // When the server and client both use default 0, then the max channel is // only limited by uint16. c.Config.ChannelMax = pick(config.ChannelMax, int(tune.ChannelMax)) @@ -919,6 +922,7 @@ func (c *Connection) openTune(config Config, auth Authentication) error { c.Config.ChannelMax = defaultChannelMax } c.Config.ChannelMax = min(c.Config.ChannelMax, maxChannelMax) + c.m.Unlock() // Frame size includes headers and end byte (len(payload)+8), even if // this is less than FrameMinSize, use what the server sends because the @@ -974,7 +978,9 @@ func (c *Connection) openComplete() error { _ = deadliner.SetDeadline(time.Time{}) } + c.m.Lock() c.allocator = newAllocator(1, c.Config.ChannelMax) + c.m.Unlock() return nil }