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

Fix concurrency issues and data race on tests #53

Closed
wants to merge 37 commits into from

Conversation

miguelreiswildlife
Copy link
Collaborator

No description provided.

@@ -411,7 +415,7 @@ func (a *APNSMessageHandler) LogStats() {
func (a *APNSMessageHandler) mapErrorReason(reason string) string {
switch reason {
case apns2.ReasonPayloadEmpty:
return "payload-empty"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was it intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. Fixed.

@@ -411,7 +415,7 @@ func (a *APNSMessageHandler) LogStats() {
func (a *APNSMessageHandler) mapErrorReason(reason string) string {
switch reason {
case apns2.ReasonPayloadEmpty:
return "payload-empty"
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we changing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was not intentional

}

//func (s *GCMMessageHandlerTestSuite) SetupSubTest() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need this? Can't we just remove?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

Comment on lines +336 to +337
s.Equal(int64(1), handler.sentMessages)
s.Equal(int64(0), handler.ignoredMessages)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need to acquire/release lock here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True


i.BufferLock.Lock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why we don't use the same .Lock() + .Unlock block for appending and clearing the buffer? Is i.deleteTokens a costly operation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No actual reason. Set everything to one lock/unlock.

if len(i.Buffer) >= i.bufferSize {
l.Debug("buffer is full")
i.deleteTokens(i.Buffer)
i.Buffer = make([]*InvalidToken, 0, i.bufferSize)
}
i.BufferLock.Unlock()
}

case <-flushTicker.C:
l.Debug("flush ticker")
i.deleteTokens(i.Buffer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't we guard deleteTokens under the .Lock() since we're changing i.Buffer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True. Good catch!

hspedro
hspedro previously approved these changes Apr 11, 2024
Copy link
Collaborator

@hspedro hspedro left a comment

Choose a reason for hiding this comment

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

LGTM, just fix the tests before merging :)

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