node-pushnotifications icon indicating copy to clipboard operation
node-pushnotifications copied to clipboard

Open handles after sending an APN notification

Open Davies-Owen opened this issue 3 years ago • 2 comments

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: '<key>',
  keyId: '<keyId>',
  teamId: '<teamId>',
  topic: '<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 = ['<iOS device token>'];
  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.

Davies-Owen avatar Apr 15 '22 16:04 Davies-Owen

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

alex-friedl avatar May 01 '22 20:05 alex-friedl

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).

edwinw6 avatar Aug 10 '23 14:08 edwinw6