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

(Potential) race condition on close #3

Open
joekarl opened this issue Jan 12, 2015 · 3 comments
Open

(Potential) race condition on close #3

joekarl opened this issue Jan 12, 2015 · 3 comments

Comments

@joekarl
Copy link
Owner

joekarl commented Jan 12, 2015

When Disconnect() is called, all that happens is the in flight buffer gets locked and then the socket is closed. The problem is if this is used in a multithreaded environment and there are any unsent payloads outside of the inflight buffer after Disconnect is called, the inflight buffer will never be flushed and there's a potential to lose whatever payload was being added as the connection was closed.

Probably just need to add an extra conditional here (https://github.com/joekarl/go-libapns/blob/master/connection.go#L299-L309) so that if the connection closed without an apple error, we return the unsent payload(s).

@joekarl
Copy link
Owner Author

joekarl commented Jan 13, 2015

Also while I'm at it, add documentation to attempt to read from the error channel for a bit after calling Disconnect()

@steeve
Copy link

steeve commented Nov 3, 2015

hey, any update on this? i've having an issue where UnsentPayloads.Len() == 0 when a wrong token is sent before a valid one. I think it may be due to that.

thanks for your hard work

@steeve
Copy link

steeve commented Nov 3, 2015

note that the error code is 251, here is a snippet:

        for {
            fmt.Println("NEW CONNECTION")
            apnsConn, _ := apns.NewAPNSConnection(&apns.APNSConfig{
                CertificateBytes: certPem,
                KeyBytes:         keyPem,
            })

        loop:
            for {
                select {
                case <-closing:
                    apnsConn.Disconnect()
                    return
                case closeError := <-apnsConn.CloseChannel:
                    fmt.Println("ERROR !!!")
                    fmt.Println(closeError.Error.ErrorCode)
                    fmt.Println(closeError.UnsentPayloads.Len())
                    break loop
                case p := <-c:
                    apnsConn.SendChannel <- p
                }
            }
        }

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

No branches or pull requests

2 participants