AndrewBarba / apns2

Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
MIT License
118 stars 32 forks source link

How to close connection? #29

Closed s-a closed 4 years ago

s-a commented 4 years ago

Hi, my node process it still running after send call. How to close connection ?

AndrewBarba commented 4 years ago

Hi, the underlying connection pool to Apples servers is what’s keeping the process running. We maintain these connections for performance reasons but I should definitely provide a close() method to disconnect.

In the mean time, is there anything wrong with calling process.exit() at the end of your script? I’ve found that to be a lot more reliable anyway, instead of tracking down every dep that might have a connection open somewhere.

s-a commented 4 years ago

Thank you for fast response. Well I plan to implement your module into an express server . So process exit is not possible. Also Unit Tests will be quite impossible. Seems after some time your pool closes. However if you point me to the right code place I can try to send a PR tomorrow.

AndrewBarba commented 4 years ago

Try calling client._clients.destroy(). That calls destroy on the underlying tarn pool and should kill all connections. Note if you do that you will not be able to send any more push notifications from that client and will need to instantiate a new one

Also note that destroy() returns a promise so you may need to await client._clients.destroy() depending on the context

s-a commented 4 years ago

Seems to work. Will try a real APN today. Thank you for your support!

AndrewBarba commented 4 years ago

I added client.destroy() to v8.4 https://github.com/AndrewBarba/apns2/releases/tag/8.4.0