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

Fix racing in Open #171

Merged
merged 2 commits into from
Feb 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,17 @@ 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))
if c.Config.ChannelMax == 0 {
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
Expand Down Expand Up @@ -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
}

Expand Down