Skip to content

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.

}
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

@sfc-gh-eraigosa sfc-gh-eraigosa 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

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

This was in fact incorrect. It makes the entire if statement into a no-op and introduced a new panic in #1227

@boyan-soubachov boyan-soubachov merged commit b5ce165 into stretchr:master Jun 24, 2022
@sfc-gh-eraigosa sfc-gh-eraigosa deleted the revert_pointer branch June 24, 2022 01:25
brackendawson added a commit to brackendawson/testify that referenced this pull request Sep 15, 2025
Previously passing a mock.Mock by value rather than by reference worked (in cases without mutex locking issues) and logged a warning. This was broken by stretchr#1212 which introduced a breaking change in an attempt to fix go vet.

There is no clean way to fix the breaking change as we now have (and want) go vet in our CI.

This PR does not revert the breaking change but changes the panic to a test failure with a useful message.
brackendawson added a commit to brackendawson/testify that referenced this pull request Sep 15, 2025
Previously passing a mock.Mock by value rather than by reference worked (in cases without mutex locking issues) and logged a warning. This was broken by stretchr#1212 which introduced a breaking change in an attempt to fix go vet.

There is no clean way to fix the breaking change as we now have (and want) go vet in our CI.

This PR does not revert the breaking change but changes the panic to a test failure with a useful message.
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.

3 participants