From 2952072f755cef70c5d97316f8ef66c53e55540d Mon Sep 17 00:00:00 2001 From: Nuno Guedelha Date: Wed, 3 Nov 2021 23:23:14 +0100 Subject: [PATCH] Issue #61: Analyse what is preventing process to exit - Close ports explicitely. - Log pending handlers and requests in the Event Loop. Reference: https://github.com/nodejs/node/issues/1128 https://github.com/thlorenz/active-handles --- iCubTelemVizServer/iCubTelemVizServer.js | 2 ++ iCubTelemVizServer/terminationHandler.js | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/iCubTelemVizServer/iCubTelemVizServer.js b/iCubTelemVizServer/iCubTelemVizServer.js index 5f0d549..418f46c 100644 --- a/iCubTelemVizServer/iCubTelemVizServer.js +++ b/iCubTelemVizServer/iCubTelemVizServer.js @@ -84,6 +84,7 @@ const TerminationHandler = require('./terminationHandler.js'); Object.keys(portInConfig).forEach(function (id) { var portIn = yarp.portHandler.open(portInConfig[id]["localName"],portInConfig[id]["portType"]); + TerminationHandler.prototype.closeNetworkPorts.push(() => {yarp.portHandler.close(portInConfig[id]["localName"])}); // Redefine the Yarp port listener switch (portInConfig[id]["portType"]) { @@ -109,6 +110,7 @@ icubtelemetry.startNotifier(); // Create RPC server for executing system commands portRPCserver4sysCmds = yarp.portHandler.open('/yarpjs/sysCmdsGenerator/rpc','rpc'); +TerminationHandler.prototype.closeNetworkPorts.push(() => {yarp.portHandler.close('/yarpjs/sysCmdsGenerator/rpc')}); portRPCserver4sysCmds.onRead(function (cmdNparams) { var cmdArray = cmdNparams.toArray(); diff --git a/iCubTelemVizServer/terminationHandler.js b/iCubTelemVizServer/terminationHandler.js index ba32b83..31afa54 100644 --- a/iCubTelemVizServer/terminationHandler.js +++ b/iCubTelemVizServer/terminationHandler.js @@ -22,7 +22,8 @@ TerminationHandler.prototype.run = function(signal) { Promise.all([subsetCpromise,subsetApromise.closeServers]).then( function(values) { values.forEach((v) => console.log(v)); - process.exit(); + // console.log(process._getActiveHandles()); + console.log(process._getActiveRequests()); } ).catch(console.error); } @@ -79,6 +80,8 @@ TerminationHandler.prototype.runSubsetB = function(resValue) { console.log('iCub Telemetry Server closing: no further "subscribe"/"unsubscribe" requests accepted.'); this.unlistenToNetworkPorts.forEach((disconnect) => { disconnect(); }); // Disconnect all telemetry entries (asynch operation) console.log('iCub Telemetry Server closing: disconnected network ports.'); + this.closeNetworkPorts.forEach((closePort) => { closePort(); }); // Close all network ports (asynch operation) + console.log('iCub Telemetry Server closing: closed network ports.'); this.icubtelemetry.stopNotifier(); return Promise.resolve('Data transmission ended.'); } @@ -97,4 +100,6 @@ TerminationHandler.prototype.runSubsetC = function(resValue) { TerminationHandler.prototype.unlistenToNetworkPorts = []; +TerminationHandler.prototype.closeNetworkPorts = []; + module.exports = TerminationHandler;