appfeel / node-pushnotifications

Push notifications for GCM, APNS, MPNS, AMZ (automatic detection from device token)
MIT License
545 stars 125 forks source link

Open handles after sending an APN notification #178

Open Davies-Owen opened 2 years ago

Davies-Owen commented 2 years ago

Current behavior:

After sending a notification via APN, node will not exit due to open handles.

Expected behavior:

The process should exit normally after all tasks are complete.

Minimal reproduction:

Click to expand ``` const PushNotifications = require('node-pushnotifications'); const apn = { key: '', keyId: '', teamId: '', topic: '', }; async function main() { const push = new PushNotifications({ apn: { production: false, token: { key: `-----BEGIN PRIVATE KEY-----\n${apn.key}\n-----END PRIVATE KEY-----`, keyId: apn.keyId, teamId: apn.teamId, }, }, }); const pushData = { alert: { body: 'Test notification', title: 'Testing', }, badge: undefined, body: 'Test notification', contentAvailable: true, custom: { sender: 'com.anybody.anywhere', }, dryRun: false, expiry: 1652452374, priority: 'high', pushType: 'alert', retries: 1, silent: false, title: 'Testing', topic: apn.topic, }; const devices = ['']; console.log('Sending push notification...'); const response = await push.send(devices, pushData); console.log(response); } main(); ```

Open handles according to why-is-node-running:

# TCPWRAP
/Users/owen/Documents/airfordable/af-ohare/packages/af-services/node_modules/@parse/node-apn/lib/client.js:121 - const session = (this.session = http2.connect(

# TLSWRAP
/Users/owen/Documents/airfordable/af-ohare/packages/af-services/node_modules/@parse/node-apn/lib/client.js:121 - const session = (this.session = http2.connect(

Thanks.

alex-friedl commented 2 years ago

Looks like it should be reported in the @parse/node-apn repo ?

edwinw6 commented 1 year ago

I was just running into this issue. For future reference: the handles remain open until the APN provider is shutdown. This doesn't seem to happen automagically, but you can force it by calling push.setOptions({}) (replace push with your instance of PushNotifications).