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

Hanging on send() #46

Open
ynnadkrap opened this issue May 14, 2015 · 4 comments
Open

Hanging on send() #46

ynnadkrap opened this issue May 14, 2015 · 4 comments

Comments

@ynnadkrap
Copy link

c.Send(m) isn't returning and I'm not sure why. I created a client without error and am not receiving any errors on sent PNs.

    c, err := apns.NewClientWithFiles(apns.SandboxGateway, CERT_PEM, KEY_PEM)
    if err != nil {
        log.Println("Client error: ", err.Error())
    }

    go func() {
        for f := range c.FailedNotifs {
            log.Println("Notif", f.Notif.ID, " failed with ", f.Err.Error())
        }
    }()

    p := apns.NewPayload()
    p.APS.Alert.Body = content
    badge := 1
    p.APS.Badge = &badge
    p.APS.Sound = "bingbong.aiff"

    m := apns.NewNotification()
    m.Payload = p
    m.DeviceToken = author.PnId
    m.Priority = apns.PriorityImmediate
    m.ID = content

    log.Println("---")
    c.Send(m)
    log.Println("...")
@nathany
Copy link
Contributor

nathany commented May 15, 2015

That's odd. All Send does is add the message to an internal channel. When you use NewClientWithFiles it also launches a goroutine with a RunLoop waiting to pull messages off that channel. I'm not sure what's happening here yet.

@taylortrimble
Copy link
Contributor

We're doing a blocking send on the notifs channel, so if the notifs channel becomes full, we'll block until a notification is dequeued.

The alternative is to use the select syntax of posting to the channel, and reporting dropped messages. Something like this.

select {
case c.notifs <- n:
    return nil;
default:
    // Send would block, drop the notification.
    return ErrNotificationDropped
}

or this:

select {
case c.notifs <- n:
default:
    // Send would block, drop the notification.
    if c.DropHandler != nil {
        c.DropHandler(n)
    }
}

@taylortrimble
Copy link
Contributor

Only read this comment if you're in the mood for crazy talk that isn't roadmapped and may never materialize:

Idea: the "drop" case could be used as a signal to open additional connections to the APNS gateway as needed for dealing with heavy load.

@nathany
Copy link
Contributor

nathany commented May 20, 2015

Yes, I'm just not sure why notifs would be blocking if there is only one notification being sent as in the example. @ynnadkrap Is there more to that example than you are showing?

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

3 participants