Description
var client = require('exceptionless').ExceptionlessClient.default;
client.config.apiKey = "***";
client.config.useDebugLogger();
This program will run and exit as expected. No events are submitted. Console output:
[info] Exceptionless: Processing queue...
franks-macbook:Exceptionless.JavaScript Frank$
Whereas, if we modify the code to submit an event:
var client = require('exceptionless').ExceptionlessClient.default;
client.config.apiKey = "***";
client.config.useDebugLogger();
client.submitLog('Test');
This program will run forever, unless you terminate it by sending SIGINT:
[info] Exceptionless: Enqueuing event: 1456470547394 type=log
[info] Exceptionless: Processing queue...
[info] Exceptionless: Sending 1 events to https://collector.exceptionless.io.
[info] Exceptionless: Sent 1 events.
[info] Exceptionless: Finished processing queue.
[info] Exceptionless: Processing queue...
[info] Exceptionless: Processing queue...
[info] Exceptionless: Processing queue...
If we npm install wtfnode
and call .dump()
, it clearly shows what's going on:
[WTF Node?] open handles:
- Sockets:
- undefined:undefined -> undefined:undefined
- Listeners:
- undefined:undefined -> undefined:undefined
- Listeners:
- Timers:
- (10000 ~ 10 s) wrapper @ /Users/Frank/Entw..../exceptionless.node.js:242
From Node docs:
In Node there is no such start-the-event-loop call. Node simply enters the event loop after executing the input script. Node exits the event loop when there are no more callbacks to perform.
So, our timer is the last single callback in Node's event loop and therefore blocks it from exiting. This is probably not an issue for service-like applications, but it sucks for console tools or anything that should just exit when the work is finished.
Thoughts:
- Can we use a shorter timespan for the timer in combination with a
lastEventTimestamp
field? - Can we leverage the same private API that
wtfnode
uses to figure out if we are the single reason that the process is still running? - How long do we want to wait for events to be submitted if the program has no work to do otherwise, before exiting? Should it wait forever if events cannot be submitted due to network problems? Should it make a difference between InMemory and LocalStorage?