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

wenlock
Copy link
Contributor

@wenlock wenlock commented Jun 23, 2022

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:

  • #1208
  • #1210
  • #1206 (introduces a workaround while keeping the new pointer)

wenlock added 4 commits Jun 23, 2022
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
@wenlock
Copy link
Contributor Author

@wenlock wenlock commented Jun 24, 2022

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

@boyan-soubachov boyan-soubachov Jun 24, 2022

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

@wenlock wenlock Jun 24, 2022

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

@wenlock wenlock Jun 24, 2022

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

@boyan-soubachov boyan-soubachov Jun 24, 2022

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

@boyan-soubachov boyan-soubachov Jun 24, 2022

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

@boyan-soubachov boyan-soubachov merged commit b5ce165 into stretchr:master Jun 24, 2022
3 checks passed
@wenlock wenlock deleted the revert_pointer branch Jun 24, 2022
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