Closed Buratti closed 4 years ago
Thanks for submitting this.
I’m curious if it’s possible Vapor 4 is the culprit. Can you show me how you are injecting the connection and config?
Also a full stack trace would be nice. :)
Sure.
class ApplePushNotificationSender {
private static let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
private var apns: APNSwiftConnection!
init() throws {
let signer = try APNSwiftSigner(filePath: Config.current.secrets.apnPath)
let apnsConfig = APNSwiftConfiguration(keyIdentifier: Config.current.apple.apnKeyIdentifier,
teamIdentifier: Config.current.apple.teamIdentifier,
signer: signer,
topic: Config.current.apple.apnTopic,
environment: Config.current.apple.apnSandbox ? .sandbox : .production)
apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: ApplePushNotificationSender.group.next()).wait()
}
@discardableResult
func send<Notification: APNSwiftNotification>(notification: Notification, to token: String) -> EventLoopFuture<Void> {
apns.send(notification, pushType: .alert, to: token)
}
}
(The try! is intended to be there to let me know if I misspelled some path in the configuration file)
struct PushNotificationService {
private let apnService = try! ApplePushNotificationSender()
@discardableResult
func broardcast<N: Notification>(notification: N, on req: Request) -> EventLoopFuture<Void> {
DeviceToken.query(on: req.db).all().flatMap { deviceTokens in
for token in deviceTokens where token.service == "apple" {
self.apnService.send(notification: notification, to: token.token)
}
return req.eventLoop.makeSucceededFuture(())
}
}
func send<N: Notification>(notification: N, to user: User, on req: Request) -> EventLoopFuture<Void> {
DeviceToken.query(on: req.db).filter(\.$owner == user.id).all().flatMap { deviceTokens in
for token in deviceTokens where token.service == "apple" {
self.apnService.send(notification: notification, to: token.token)
}
return req.eventLoop.makeSucceededFuture(())
}
}
}
And in the end I just register the service in the configure.swift
file of Vapor.
app.register(instance: PushNotificationService())
Current stack trace:
0 libswiftCore.so 0x00007f5a0bde5ec0 swift_reportError + 50
1 libswiftCore.so 0x00007f5a0be56f60 _swift_stdlib_reportFatalErrorInFile + 115
2 libswiftCore.so 0x00007f5a0bd7af0e <unavailable> + 3514126
3 libswiftCore.so 0x00007f5a0bd7b087 <unavailable> + 3514503
4 libswiftCore.so 0x00007f5a0bb7082d <unavailable> + 1374253
5 libswiftCore.so 0x00007f5a0bd51e68 <unavailable> + 3346024
6 libswiftCore.so 0x00007f5a0bb6fbc9 <unavailable> + 1371081
7 Run 0x000055ab46793920 <unavailable> + 6609184
8 Run 0x000055ab4684762e <unavailable> + 7345710
9 Run 0x000055ab468475a8 <unavailable> + 7345576
10 Run 0x000055ab46793316 <unavailable> + 6607638
11 Run 0x000055ab46793b57 <unavailable> + 6609751
12 libswiftCore.so 0x00007f5a0bde79ab <unavailable> + 3959211
13 Run 0x000055ab4624365b <unavailable> + 1037915
14 Run 0x000055ab46242adf <unavailable> + 1034975
15 Run 0x000055ab463124b1 <unavailable> + 1885361
16 Run 0x000055ab4630e151 <unavailable> + 1868113
17 Run 0x000055ab4630da1f <unavailable> + 1866271
18 Run 0x000055ab46794155 <unavailable> + 6611285
19 Run 0x000055ab4678f8b0 <unavailable> + 6592688
20 Run 0x000055ab4678fdd1 <unavailable> + 6594001
21 Run 0x000055ab4678f293 <unavailable> + 6591123
22 Run 0x000055ab46790a8c <unavailable> + 6597260
23 Run 0x000055ab4679149b <unavailable> + 6599835
24 Run 0x000055ab46791381 <unavailable> + 6599553
25 Run 0x000055ab46ae5e10 <unavailable> + 10092048
26 Run 0x000055ab46ae6861 <unavailable> + 10094689
27 Run 0x000055ab46ae70e9 <unavailable> + 10096873
28 Run 0x000055ab4674233a <unavailable> + 6275898
29 Run 0x000055ab467423cb <unavailable> + 6276043
30 Run 0x000055ab46745fb3 <unavailable> + 6291379
31 Run 0x000055ab46b19d5b <unavailable> + 10304859
32 Run 0x000055ab46b1a6f3 <unavailable> + 10307315
33 Run 0x000055ab4676207d <unavailable> + 6406269
34 Run 0x000055ab4676a0ed <unavailable> + 6439149
35 Run 0x000055ab46760bae <unavailable> + 6400942
36 Run 0x000055ab4676192a <unavailable> + 6404394
37 Run 0x000055ab4676373c <unavailable> + 6412092
38 Run 0x000055ab46764089 <unavailable> + 6414473
39 Run 0x000055ab4674233a <unavailable> + 6275898
40 Run 0x000055ab4673ddfd <unavailable> + 6258173
41 Run 0x000055ab46702529 <unavailable> + 6014249
42 Run 0x000055ab466fa666 <unavailable> + 5981798
43 Run 0x000055ab466fbcfd <unavailable> + 5987581
44 Run 0x000055ab466fd1e9 <unavailable> + 5992937
45 Run 0x000055ab46781d99 <unavailable> + 6536601
46 Run 0x000055ab46782f2e <unavailable> + 6541102
47 Run 0x000055ab467832a9 <unavailable> + 6541993
48 Run 0x000055ab4678df94 <unavailable> + 6586260
49 Run 0x000055ab4680e18b <unavailable> + 7111051
50 Run 0x000055ab46782c2a <unavailable> + 6540330
51 Run 0x000055ab4678a194 <unavailable> + 6570388
52 Run 0x000055ab46556eaf <unavailable> + 4263599
53 Run 0x000055ab4678a1b4 <unavailable> + 6570420
54 Run 0x000055ab4677f412 <unavailable> + 6525970
55 Run 0x000055ab467821d6 <unavailable> + 6537686
56 Run 0x000055ab46785905 <unavailable> + 6551813
57 Run 0x000055ab4678dbfa <unavailable> + 6585338
58 Run 0x000055ab46785f3f <unavailable> + 6553407
59 Run 0x000055ab46845961 <unavailable> + 7338337
60 Run 0x000055ab46845df1 <unavailable> + 7339505
61 Run 0x000055ab46845eb9 <unavailable> + 7339705
62 libpthread.so.0 0x00007f5a0b8096db <unavailable> + 30427
63 libc.so.6 0x00007f5a09c74850 clone + 63
I don't think it is relevant but a couple of additional informations:
The app is running on a Digital Ocean droplet with 1 core and 1 GB of memory. I am using Supervisor to keep the service up.
$ swift --version
Swift version 5.1 (swift-5.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
$ cat Package.resolved
{
"object": {
"pins": [
{
"package": "apnswift",
"repositoryURL": "https://github.com/kylebrowning/APNSwift.git",
"state": {
"branch": null,
"revision": "a4884ba916202aed3497ea555e59215b0bde9e65",
"version": "1.3.0"
}
},
{
"package": "async-http-client",
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
"state": {
"branch": null,
"revision": "51dc885a30ca704b02fa803099b0a9b5b38067b6",
"version": "1.0.0"
}
},
{
"package": "async-kit",
"repositoryURL": "https://github.com/vapor/async-kit.git",
"state": {
"branch": null,
"revision": "d9fd2be441af6d1428b62ab694848396e7072a14",
"version": "1.0.0-beta.1"
}
},
{
"package": "Cryptor",
"repositoryURL": "https://github.com/IBM-Swift/BlueCryptor.git",
"state": {
"branch": null,
"revision": "12d2bf3ec7207ec3cd004b9582f69ef5fae1da3b",
"version": "1.0.32"
}
},
{
"package": "CryptorECC",
"repositoryURL": "https://github.com/IBM-Swift/BlueECC.git",
"state": {
"branch": null,
"revision": "73f362cb0d9c5f1fd0089240d7b293cd2bff18db",
"version": "1.2.5"
}
},
{
"package": "CryptorRSA",
"repositoryURL": "https://github.com/IBM-Swift/BlueRSA.git",
"state": {
"branch": null,
"revision": "e906f5e93426bb43ad7ac37cc20008d8fae608d9",
"version": "1.0.34"
}
},
{
"package": "console-kit",
"repositoryURL": "https://github.com/vapor/console-kit.git",
"state": {
"branch": null,
"revision": "5b91c2dc93781e4b36cb4c667972670eac90e6e7",
"version": "4.0.0-beta.1"
}
},
{
"package": "fluent",
"repositoryURL": "https://github.com/vapor/fluent.git",
"state": {
"branch": null,
"revision": "96f2ab8599b0507ba593da80ba2c56101932679b",
"version": "4.0.0-beta.1"
}
},
{
"package": "fluent-kit",
"repositoryURL": "https://github.com/vapor/fluent-kit.git",
"state": {
"branch": null,
"revision": "2907bfd11743909c63ccde89cb2c66b1c8d1d645",
"version": "1.0.0-beta.1"
}
},
{
"package": "fluent-postgres-driver",
"repositoryURL": "https://github.com/vapor/fluent-postgres-driver",
"state": {
"branch": null,
"revision": "cc9d712aa6f4c2b667170a982c7c3020c03ef08a",
"version": "2.0.0-beta.1.1"
}
},
{
"package": "KituraContracts",
"repositoryURL": "https://github.com/IBM-Swift/KituraContracts.git",
"state": {
"branch": null,
"revision": "a30e2fb79e926672776a05ec6b919c239870a221",
"version": "1.2.1"
}
},
{
"package": "LoggerAPI",
"repositoryURL": "https://github.com/IBM-Swift/LoggerAPI.git",
"state": {
"branch": null,
"revision": "3357dd9526cdf9436fa63bb792b669e6efdc43da",
"version": "1.9.0"
}
},
{
"package": "multipart-kit",
"repositoryURL": "https://github.com/vapor/multipart-kit.git",
"state": {
"branch": null,
"revision": "a941d7a1d685c83df09077f6190808ff2a7f4dce",
"version": "4.0.0-beta.1"
}
},
{
"package": "open-crypto",
"repositoryURL": "https://github.com/vapor/open-crypto.git",
"state": {
"branch": null,
"revision": "06d26edb8e28295bb7103b4f950d5ea58d634c1b",
"version": "4.0.0-alpha.2"
}
},
{
"package": "OpenSSL",
"repositoryURL": "https://github.com/IBM-Swift/OpenSSL.git",
"state": {
"branch": null,
"revision": "6c7e2e3610037fbc05c0d846cec981518961d8bf",
"version": "2.2.2"
}
},
{
"package": "postgres-kit",
"repositoryURL": "https://github.com/vapor/postgres-kit.git",
"state": {
"branch": null,
"revision": "b264d62a5dde67dd2e71745fbe70161d733e417f",
"version": "2.0.0-beta.1"
}
},
{
"package": "postgres-nio",
"repositoryURL": "https://github.com/vapor/postgres-nio.git",
"state": {
"branch": null,
"revision": "1fc1c201588ee5f0b1272887b18b69caba67edaa",
"version": "1.0.0-alpha.1.6"
}
},
{
"package": "routing-kit",
"repositoryURL": "https://github.com/vapor/routing-kit.git",
"state": {
"branch": null,
"revision": "6c7f4b471f9662d05045d82e64e22d5572a16a82",
"version": "4.0.0-alpha.1"
}
},
{
"package": "sql-kit",
"repositoryURL": "https://github.com/vapor/sql-kit.git",
"state": {
"branch": null,
"revision": "2a05245bd3b1a27acc83597dca25ac52358073e5",
"version": "3.0.0-beta.1"
}
},
{
"package": "SwiftJWT",
"repositoryURL": "https://github.com/IBM-Swift/Swift-JWT.git",
"state": {
"branch": null,
"revision": "2241e8371092c12ed2095de2ad06ce27103eba53",
"version": "3.6.0"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "74d7b91ceebc85daf387ebb206003f78813f71aa",
"version": "1.2.0"
}
},
{
"package": "swift-metrics",
"repositoryURL": "https://github.com/apple/swift-metrics.git",
"state": {
"branch": null,
"revision": "3fefedaaef285830cc98ae80231140122076a7e0",
"version": "1.2.0"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "ff01888051cd7efceb1bf8319c1dd3986c4bf6fc",
"version": "2.10.1"
}
},
{
"package": "swift-nio-extras",
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
"state": {
"branch": null,
"revision": "53808818c2015c45247cad74dc05c7a032c96a2f",
"version": "1.3.2"
}
},
{
"package": "swift-nio-http2",
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
"state": {
"branch": null,
"revision": "7cc32a9a41e348230a4a452b25b7308cae1f3652",
"version": "1.7.1"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "ccf96bbe65ecc7c1558ab0dba7ffabdea5c1d31f",
"version": "2.4.4"
}
},
{
"package": "vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "3d8bbd5eb2b556debbb51da8ac7357f34b7b0a8e",
"version": "4.0.0-beta.1"
}
},
{
"package": "websocket-kit",
"repositoryURL": "https://github.com/vapor/websocket-kit.git",
"state": {
"branch": null,
"revision": "66c0ea58398f055b5a0d92b0d5f4c32ef0c02eeb",
"version": "2.0.0-beta.1"
}
}
]
},
"version": 1
}
Any chance you can dsym that stack trace?
@Buratti Can you point your project at a branch of mine and test? apns-errors
@Buratti Ive updated the apns-errors
branch if you'd like to give it a whirl.
I am running a Vapor 4 app on Ubuntu 18.04 with APNSwift 1.3.0.
As of now I just send a simple notification as described in the getting started page of this repo.
I don't know if it is a coincidence but I noticed that the fatal error appears only after a couple of hours without interacting with the service.
Please let me know if I can give you other informations, it is quite a complicated bug to reproduce.