-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2: Server processes do not close and exit properly when terminated from the terminal #34
Comments
Originally posted by @nunoguedelha in #25 (comment) |
Capturing SIGINT signal event: AnalysisThe issue of SIGINT not being captured by the implemented listener might be related to the maximum number of listeners being occasionally exceeded. Indeed we sometimes get the warning:
Although the warning is not systematically emitted, this deserves some further investigation.
ReferencesEvents Emitted by Node.js when Signal Received
Signal listeners and Class EventEmitter
|
Capturing SIGINT signal event: Root cause and FixRoot causeAs we described previously, the issue was due to the fact that two listeners are registered for the event 'SIGINT`, and ours does not come first in the list. listeners count for event SIGINT: 2
function (){
process.exit();
}
() => {console.log('Received ',myEvent);} Actually, the first one is not a default listener*, it has been added by one of the packets included in the main script (*) The default listener associated to an event is called when no other listener is added for that event, and is replaced by added events. By dichotomy, counting the listeners before and after a code block, we narrowed down the search to the line var yarp = require('YarpJS'); More precisely in the installed file // make sure to close stuff when Ctrl+C arrives
process.on('SIGINT',function(){
process.exit();
});
// make sure to close stuff when closing signal arrives
process.on('SIGTERM',function(){
process.exit();
}); which could have been found by a simple grep on SIGINT actually, but the first search method is more deterministic. FixWe have two possible approaches:
But We add to the top of the main script: process.on('SIGQUIT', () => {closeServers('SIGQUIT');});
process.once('SIGTERM', () => {closeServers('SIGTERM');});
process.once('SIGINT', () => {closeServers('SIGINT');}); We use NoteThe function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
} This content can be get by displaying the signal event callback as described in #34 (comment). |
Processing the SIGINT event: closeServers(signal) functionThe function
Moved to #40 . |
References on Node.js
How to properly exit a Node.js processAvoid process.exit()https://stackoverflow.com/questions/5266152/how-to-exit-in-node-js
https://nodejs.dev/learn/how-to-exit-from-a-nodejs-program
The stepshttps://nodejs.dev/learn/how-to-exit-from-a-nodejs-program Node.js
|
The main problem with the server closure seems to come from the fact that if the telemetry server is created as follows: const telemServer = app.listen(portTelemetryRespOrigin, function () {
console.log('ICubTelemetry History hosted at http://localhost:' + portTelemetryRespOrigin + '/history');
console.log('ICubTelemetry Realtime hosted at ws://localhost:' + portTelemetryRespOrigin + '/realtime');
}); and for stopping it, we should do: telemServer.close(() => {
console.log('iCub Telemetry Server closed. No further incoming requests accepted.');
}) but the Or maybe the event |
The reason was that We need to use |
References on Express and Express-ws, routing etcMainApp, Routerhttps://expressjs.com/en/4x/api.html#app The app object conventionally denotes the Express application. Create it by calling the top-level express() function exported by the Express module. https://expressjs.com/en/4x/api.html#router Using middlewarehttps://expressjs.com/en/guide/using-middleware.html Express is a routing and middleware web framework that has minimal functionality of its own: An Express application is essentially a series of middleware function calls. Middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next. Middleware functions can perform the following tasks:
Routinghttps://expressjs.com/en/guide/routing.html app.METHOD(path, callback [, callback ...])https://expressjs.com/en/4x/api.html#app.METHOD Routes the HTTP method "METHOD" (in lowercase) request to the specified path with the specified callback functions.
... app.use([path,] callback [, callback...])https://expressjs.com/en/4x/api.html#app.use Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path. A route will match any path that follows its path immediately with a “/”. For example: app.use('/apple', ...) will match “/apple”, “/apple/images”, “/apple/images/news”, and so on. Hypertext Transfer Protocol (authentication, request methods)https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods express-wsThe following code snipport var router = express.Router();
router.ws('/', function (ws) {...}; calls websockethttps://github.com/websockets/ws/blob/master/doc/ws.md websocket.readyState : {Number} The current state of the connection. This is one of the ready state constants. Ready state constants
We should check that websocket.readyState === websocket.OPEN (= 1) before sending any data. Javascript Async and Promiseshttps://www.w3schools.com/js/js_async.asp
|
Refer to #33 :
Further Details on the Affected Components and Conditions
iCubTelemVizServer
which creates connections with the YARP ports and the requests from the client browser through socket connections, unlike theopenmctStaticServer
. The later handles the Open MCT libraries installation on the remote client browser, along with the dictionary of telemetry entries and the Open MCT plugins associating the GUI widgets to the http (history and realtime) requests sent toiCubTelemVizServer
.iCubTelemVizServer
is running alone, andopenmctStaticServer
is never started, not even from the terminal.Implementation Steps & issues
The text was updated successfully, but these errors were encountered: