swift-server-community / APNSwift

📱HTTP/2 Apple Push Notification Service built with swift - send push notifications to iOS, iPadOS, tvOS, macOS, watchOS, visionOS, and Safari!
Apache License 2.0
695 stars 105 forks source link

[BUG] 2.2.0 Infinite Recursion #100

Closed nicktrienensfuzz closed 3 years ago

nicktrienensfuzz commented 3 years ago

Describe the bug send class it's self to maximum stack size in xcode

To Reproduce included via .package(url: "https://github.com/vapor/apns.git", from: "1.0.0")

app.get("test") { req -> String in
        try app.apns.send(
            .init(title: "Hello", subtitle: "This is a test from vapor/apns"),
            to: "6a9201adcaa835-------------3"
        ).wait()
        return "Hello, world!"
}

This function seems to call it's self forever

public func send(rawBytes payload: ByteBuffer,
                     pushType: APNSwiftConnection.PushType = .alert,
                     to deviceToken: String,
                     expiration: Date? = nil,
                     priority: Int? = nil,
                     collapseIdentifier: String? = nil,
                     topic: String? = nil,
                     logger: Logger? = nil,
                     apnsID: UUID? = nil) -> EventLoopFuture<Void> {
        return self.send(
            rawBytes: payload,
            pushType: pushType,
            to: deviceToken,
            expiration: expiration,
            priority: priority,
            collapseIdentifier: collapseIdentifier,
            topic: topic,
            logger: logger ?? self.logger,
            apnsID: apnsID)
    }

Expected behavior Hope to see a sent notification

Screenshots Screen Shot 2021-01-08 at 11 07 45 AM

Platform:

Additional context Add any other context about the problem here.

kylebrowning commented 3 years ago

can you try with 2.1.0 so we can rule out its not the recent release?

kylebrowning commented 3 years ago

Sorry I meant 2.1.0

kylebrowning commented 3 years ago

@mackoj This is related to what we just merged, I've deleted 2.2.0 for now.

mackoj commented 3 years ago

Ok thanks @kylebrowning I will look into it sorry @nicktrienensfuzz for the bug

mackoj commented 3 years ago

Hi, @nicktrienensfuzz sorry for the inconvenience but I did't succeed reproducing this bug, maybe you can help me to reproduce it.

I have cloned https://github.com/vapor/apns.git run APNSTests and change APNSwiftConfiguration to something that will work and add my device token and it's working.

I have cloned https://github.com/kylebrowning/APNSwift and try it's test APNSwiftExample and change APNSwiftConfiguration to something that will work and add my device token and it's working. I have tried all send variation and didn't reproduce this bug.

In both cases I did received the notifications.

nicktrienensfuzz commented 3 years ago

I used this sample code from the vapor doc site, https://docs.vapor.codes/4.0/apns/

try app.apns.send(
            .init(title: "Hello", subtitle: "This is a test from vapor/apns"),
            to: "6a9201adcaa835-------------3"
        )
nicktrienensfuzz commented 3 years ago

it is working now, using 2.1.0 Looks like it might have been bad usage on my part too, I was using that in a route so I should have been accessing the .apns property on the Request

   app.get("test") { req in
        req.apns.send(
            .init(title: "Hello", subtitle: "This is a test from vapor/apns"),
            to: "6a9201adcaa8358e92a01d5e1ba0ccdaad061ccfb7797293da53df807c1c53"
        ).map { "sent" }
    }
nicktrienensfuzz commented 3 years ago

Thank you so much for your quick response

kylebrowning commented 3 years ago

This issue still exists in master.

mackoj commented 3 years ago

I'm reproducing it now and working on a fix.

mackoj commented 3 years ago

@kylebrowning and @nicktrienensfuzz I tried to explain the issue and give a fix here.

https://github.com/vapor/apns/pull/27

kylebrowning commented 3 years ago

I think this is resolved.