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

fixing panic in calls to assertion with nil m.mutex #1212

Merged
merged 4 commits into from Jun 24, 2022

Conversation

sfc-gh-eraigosa
Copy link
Contributor

Summary

@CleanCut and I found these changes that should be reverted as they are causing panics after library updates.

This reverts a change that was made in #1182
That PR makes m.mutex a pointer which now needs to be checked but it's not checked for nil everywhere.
It also reset the mutex in the .On function when it could actually have locks from other callers.

Changes

  • revert m.mutex back to a non pointer value
  • don't throw away the lock that might be used concurrently in the .On function

Motivation

Fixing panics and crashes in the library after a minor update.

Related issues

This should also help with these issues:

Edward Raigosa added 4 commits June 23, 2022 18:06
This reverts a change that was made in stretchr#1182
The PR makes m.mutex a pointer which now needs to be checked but it's not checked for nil everywhere.

This should also help with these issues:
- stretchr#1208
- stretchr#1210
@sfc-gh-eraigosa
Copy link
Contributor Author

Hey @boyan-soubachov sorry to ping you directly but since you were the original author for #1182 I thought I'd bring this one to your attention. Thanks for any review you might be able to offer.

@@ -526,9 +519,9 @@ func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
h.Helper()
}
for _, obj := range testObjects {
if m, ok := obj.(Mock); ok {
if m, ok := obj.(*Mock); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this should be changed? IIRC I didn't change this logic in the PR I merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because we want to refer to the same instance of sync.Mutex for the copy that is a type check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, go vet ./... will show that warning for us ( It was caught in CI).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough; I see it's a test helper anyways.

Thank you for catching this!

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤦 . I must've missed this when doing the Go 1.18 PR (which broke this) and 'fixed it' the long way around. Thanks

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.

None yet

2 participants