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

Some unit tests in connection were showing a race condition (see #31): #56

Closed

Conversation

DanielePalaia
Copy link
Contributor

These ones were the ones testing Open scenarios. The issue is that Open and Close, rwc.Open and rwc.Close can at the same time write on:

c.allocator = newAllocator(1, c.Config.ChannelMax)
connection.go line 444 and
connection.go line 849

while shutdown is protected by the structure mutex m, OpenComplete() is not causing the race.

While it's not clear if the library should protect this eventuality, the tests are testing the Open function, so I think the close can be put in the main thread avoiding the race and not affecting the test validity

…itmq#31):

These ones were the ones testing Open scenarios. The issue is that Open and Close, rwc.Open and rwc.Close can at the same time write on:

c.allocator = newAllocator(1, c.Config.ChannelMax)
connection.go line 444 and
connection.go line 849

while shutdown is protected by the structure mutex m, OpenComplete() is not causing the race.

While it's not clear if the library should protect this eventuality, the tests are testing the Open function, so I think the close can be put in the main thread avoiding the race and not affecting the test validity
Copy link
Contributor

@Zerpet Zerpet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this approach is that t.Fatalf() stops the execution of the function, and in that case, Close() will never be called, potentially leaving open connections behind.

I would place the Close() call in a t.Cleanup() call to ensure it is called, regardless of the result of the test.

@Zerpet Zerpet linked an issue Mar 25, 2022 that may be closed by this pull request
DanielePalaia and others added 3 commits March 25, 2022 14:23
Co-authored-by: Daniele Palaia <dpalaia@dpalaia-a02.vmware.com>
…rsion file to manage versioning (rabbitmq#54)

Co-authored-by: Daniele Palaia <dpalaia@dpalaia-a02.vmware.com>
@DanielePalaia
Copy link
Contributor Author

@Zerpet good idea put it in all TestOpen tests

@Zerpet
Copy link
Contributor

Zerpet commented Mar 25, 2022

We should call t.Cleanup() at the begining of the test, as soon as possible, not at the end 😄

I'm not sure about including f781c65 and 9bfc51b in this PR. I agree those are useful, but I don't see how they are relevant to the race condition 🤔

@DanielePalaia
Copy link
Contributor Author

Superseded by #57

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

Successfully merging this pull request may close these issues.

Potential race condition in Connection module
2 participants