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

Synchronous Barrier call holds conn mutex #345

Closed
nussjustin opened this issue Mar 4, 2018 · 1 comment
Closed

Synchronous Barrier call holds conn mutex #345

nussjustin opened this issue Mar 4, 2018 · 1 comment
Assignees
Labels
bug Confirmed reproducible bug

Comments

@nussjustin
Copy link
Contributor

When Barrier is called with no active asynchronous subscriptions, the call will be made synchronously with both nc.mu and nc.subsMu held. Calling any other method on the Conn in the callback will than block the whole connection.

E.g. calling

conn, _ := nats.Connect("nats://127.0.0.1:4222")
conn.Barrier(func() {
	conn.TLSRequired()
})

will block since the callback is called synchronously in Barrier, which holds the two mutexes.

As long as there is at least one asynchronous subscription, the callback will be called later without any mutex held. So this will work:

conn, _ := nats.Connect("nats://127.0.0.1:4222")
conn.Subscribe("nats_is_awesome", func(_ *nats.Msg) {})
conn.Barrier(func() {
	conn.TLSRequired()
})
@kozlovic kozlovic self-assigned this Mar 4, 2018
@kozlovic kozlovic added the bug Confirmed reproducible bug label Mar 4, 2018
kozlovic added a commit that referenced this issue Mar 4, 2018
@kozlovic
Copy link
Member

kozlovic commented Mar 4, 2018

@nussjustin Thanks again for an excellent report (and catch!). I had originally started f as a go-routine but decided at the last minute that there was no need really. However, you are right, in this case I should have released the locks. The PR #346 addresses that. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed reproducible bug
Projects
None yet
Development

No branches or pull requests

2 participants