Skip to content

Commit

Permalink
Issue #61: Analyse what is preventing process to exit
Browse files Browse the repository at this point in the history
- Close ports explicitely.
- Log pending handlers and requests in the Event Loop.
  Reference:
  nodejs/node#1128
  https://github.com/thlorenz/active-handles
  • Loading branch information
nunoguedelha committed Nov 3, 2021
1 parent b07deb5 commit 2952072
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions iCubTelemVizServer/iCubTelemVizServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) {
Expand All @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion iCubTelemVizServer/terminationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.');
}
Expand All @@ -97,4 +100,6 @@ TerminationHandler.prototype.runSubsetC = function(resValue) {

TerminationHandler.prototype.unlistenToNetworkPorts = [];

TerminationHandler.prototype.closeNetworkPorts = [];

module.exports = TerminationHandler;

0 comments on commit 2952072

Please sign in to comment.