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

Remove unnecessary lock of changeState #631

Merged

Conversation

BewareMyPower
Copy link
Contributor

@BewareMyPower BewareMyPower commented Oct 4, 2021

Motivation

There's no need to lock the changeState method. We don't need the whole operation is atomic. Instead, we just need that c.setState(state) takes effect so that c.cond.Broadcast() can broadcast the correct notification that the state has been changed successfully. #451 changed state field to an atomic variable, so we don't need the lock for changing state anymore.

I guess the lock for changeState was added when the state field was just a normal int32 variable. But #451 didn't remove the lock.

Modifications

Remove the Lock()/Unlock() calls in changeState, then reuse changeState in connection.Close().

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

@BewareMyPower BewareMyPower self-assigned this Oct 4, 2021
@BewareMyPower BewareMyPower added this to the 0.7.0 milestone Oct 4, 2021
@BewareMyPower
Copy link
Contributor Author

There's a CI failure caused by

go: gopkg.in/[email protected]: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /pkg/mod/cache/vcs/7e5fa1eab4705eb80c9746632736cea906708d060702d529df6241d1c8c2c9f9: exit status 128:
	fatal: unable to access 'https://gopkg.in/check.v1/': server certificate verification failed. CAfile: none CRLfile: none
go: error loading module requirements

@BewareMyPower BewareMyPower force-pushed the bewaremypower/remove-conn-locks branch from 6835563 to 39ed9b9 Compare October 5, 2021 05:34
Copy link
Contributor

@freeznet freeznet left a comment

Choose a reason for hiding this comment

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

LGTM

@freeznet freeznet merged commit a28dbd4 into apache:master Oct 9, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/remove-conn-locks branch October 9, 2021 03:26
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