I have a plugin for a Hapi.js-based REST service that is sending logging data to a log ingestion API.
When the Hapi REST service generates a large volume of logging data, the log ingestion API can't handle the volume and I see socket disconnected errors from my plugin.
I can eliminate the socket disconnect errors by configuring a maxSockets property on the HTTP agent, but the problem now is that it takes minutes for the sockets to be freed new data to be sent by the plugin to the log ingestion API.
For example, if I configure maxSockets as 50 and send 200 requests to the Hapi REST service, the first 50 log events show up in the log ingestion endpoint right away.
The next 50 events start to trickle in after 5-10 minutes ... and so on.
My question is how to do debugging to understand the life cycle of the sockets and find out why they are apparently taking so long to be freed.
Everything I've read (e.g. node.js what happens when maxSockets are reached? and Node JS how to limit maximum number of sockets) describes that maxSockets queues the number of concurrent sockets, but nothing in more detail about how that queueing works.