When server.close is called, there are two properties that are checked.
handle<tcp handle>
connections
Responsible code fragment of server.close responsible for this error;
if (!this._handle) {
// Throw error. Follows net_legacy behaviour.
throw new Error('Not running');
}
Only if handle===null and connections ===0 that the callback passed to close is called.
Case : Server is started and sent the signal with no serving.
Before close is called;
handle === TCP handle.
connection===0;
After close handle===null; connection===0;
The callback gets called.
Case : Server is started and sent the signal after a request server.
Before close is called;
handle === TCP.handle;
connection===1;
After close handle === null; connection===1;
No callback is fired.
Second time when you press ctrl-c
Before close is called;
handle === null;
connection===1;
since handle===null , the check throws the error you are seeing.