@comunica/actor-init-query 2.2.2-alpha.18.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/HttpServiceSparqlEndpoint.js +29 -17
- package/package.json +15 -15
|
@@ -149,7 +149,9 @@ class HttpServiceSparqlEndpoint {
|
|
|
149
149
|
workerTimeouts[queryId] = setTimeout(() => {
|
|
150
150
|
stderr.write(`Worker ${worker.process.pid} timed out for query ${queryId}.\n`);
|
|
151
151
|
try {
|
|
152
|
-
worker.
|
|
152
|
+
if (worker.isConnected()) {
|
|
153
|
+
worker.send('shutdown');
|
|
154
|
+
}
|
|
153
155
|
}
|
|
154
156
|
catch (error) {
|
|
155
157
|
stderr.write(`Unable to timeout worker ${worker.process.pid}: ${error.message}.\n`);
|
|
@@ -185,6 +187,28 @@ class HttpServiceSparqlEndpoint {
|
|
|
185
187
|
const server = http.createServer(this.handleRequest.bind(this, engine, variants, stdout, stderr));
|
|
186
188
|
server.listen(this.port);
|
|
187
189
|
stderr.write(`Server worker (${process.pid}) running on http://localhost:${this.port}/sparql\n`);
|
|
190
|
+
// Keep track of all open connections
|
|
191
|
+
const openConnections = new Set();
|
|
192
|
+
server.on('request', (request, response) => {
|
|
193
|
+
openConnections.add(response);
|
|
194
|
+
response.on('close', () => {
|
|
195
|
+
openConnections.delete(response);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
// Subscribe to shutdown messages
|
|
199
|
+
process.on('message', async (message) => {
|
|
200
|
+
if (message === 'shutdown') {
|
|
201
|
+
stderr.write(`Shutting down worker ${process.pid} with ${openConnections.size} open connections.\n`);
|
|
202
|
+
// Stop new connections from being accepted
|
|
203
|
+
server.close();
|
|
204
|
+
// Close all open connections
|
|
205
|
+
for (const connection of openConnections) {
|
|
206
|
+
await new Promise(resolve => connection.end('!TIMEDOUT!', resolve));
|
|
207
|
+
}
|
|
208
|
+
// Kill the worker once the connections have been closed
|
|
209
|
+
process.exit(15);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
188
212
|
}
|
|
189
213
|
/**
|
|
190
214
|
* Handles an HTTP request.
|
|
@@ -305,20 +329,6 @@ class HttpServiceSparqlEndpoint {
|
|
|
305
329
|
}
|
|
306
330
|
// Send message to master process to indicate the start of an execution
|
|
307
331
|
process.send({ type: 'start', queryId });
|
|
308
|
-
// Listen for shutdown events from master for timeouts
|
|
309
|
-
const messageListener = (message) => {
|
|
310
|
-
if (message === 'shutdown') {
|
|
311
|
-
response.end('!TIMEDOUT!', () => {
|
|
312
|
-
// Wait a bit after sending response end, to make sure that all other responses have also been ended
|
|
313
|
-
setTimeout(() => {
|
|
314
|
-
stderr.write(`Shutting down worker ${process.pid} for query ${queryId}.\n`);
|
|
315
|
-
// eslint-disable-next-line unicorn/no-process-exit
|
|
316
|
-
process.exit(9);
|
|
317
|
-
}, 1000);
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
process.on('message', messageListener);
|
|
322
332
|
let eventEmitter;
|
|
323
333
|
try {
|
|
324
334
|
const { data } = await engine.resultToString(result, mediaType);
|
|
@@ -336,7 +346,6 @@ class HttpServiceSparqlEndpoint {
|
|
|
336
346
|
}
|
|
337
347
|
// Send message to master process to indicate the end of an execution
|
|
338
348
|
response.on('close', () => {
|
|
339
|
-
process.removeListener('message', messageListener);
|
|
340
349
|
process.send({ type: 'end', queryId });
|
|
341
350
|
});
|
|
342
351
|
this.stopResponse(response, queryId, eventEmitter);
|
|
@@ -405,6 +414,9 @@ class HttpServiceSparqlEndpoint {
|
|
|
405
414
|
if (eventEmitter) {
|
|
406
415
|
// Remove all listeners so we are sure no more write calls are made
|
|
407
416
|
eventEmitter.removeAllListeners();
|
|
417
|
+
eventEmitter.on('error', () => {
|
|
418
|
+
// Void any errors that may still occur
|
|
419
|
+
});
|
|
408
420
|
eventEmitter.emit('end');
|
|
409
421
|
}
|
|
410
422
|
try {
|
|
@@ -417,7 +429,7 @@ class HttpServiceSparqlEndpoint {
|
|
|
417
429
|
if (self.freshWorkerPerQuery) {
|
|
418
430
|
process.stderr.write(`Killing fresh worker ${process.pid} after query ${queryId}.\n`);
|
|
419
431
|
// eslint-disable-next-line unicorn/no-process-exit
|
|
420
|
-
process.exit(
|
|
432
|
+
process.exit(15);
|
|
421
433
|
}
|
|
422
434
|
}
|
|
423
435
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-init-query",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A query init actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,19 +31,19 @@
|
|
|
31
31
|
"lib/**/*.js"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@comunica/actor-http-proxy": "2.
|
|
35
|
-
"@comunica/bus-context-preprocess": "2.
|
|
36
|
-
"@comunica/bus-http-invalidate": "2.
|
|
37
|
-
"@comunica/bus-init": "2.
|
|
38
|
-
"@comunica/bus-optimize-query-operation": "2.
|
|
39
|
-
"@comunica/bus-query-operation": "2.
|
|
40
|
-
"@comunica/bus-query-parse": "2.
|
|
41
|
-
"@comunica/bus-query-result-serialize": "2.
|
|
42
|
-
"@comunica/context-entries": "2.
|
|
43
|
-
"@comunica/core": "2.
|
|
44
|
-
"@comunica/logger-pretty": "2.
|
|
45
|
-
"@comunica/runner": "2.
|
|
46
|
-
"@comunica/types": "2.
|
|
34
|
+
"@comunica/actor-http-proxy": "^2.3.0",
|
|
35
|
+
"@comunica/bus-context-preprocess": "^2.3.0",
|
|
36
|
+
"@comunica/bus-http-invalidate": "^2.3.0",
|
|
37
|
+
"@comunica/bus-init": "^2.3.0",
|
|
38
|
+
"@comunica/bus-optimize-query-operation": "^2.3.0",
|
|
39
|
+
"@comunica/bus-query-operation": "^2.3.0",
|
|
40
|
+
"@comunica/bus-query-parse": "^2.3.0",
|
|
41
|
+
"@comunica/bus-query-result-serialize": "^2.3.0",
|
|
42
|
+
"@comunica/context-entries": "^2.3.0",
|
|
43
|
+
"@comunica/core": "^2.3.0",
|
|
44
|
+
"@comunica/logger-pretty": "^2.3.0",
|
|
45
|
+
"@comunica/runner": "^2.3.0",
|
|
46
|
+
"@comunica/types": "^2.3.0",
|
|
47
47
|
"@rdfjs/types": "*",
|
|
48
48
|
"@types/yargs": "^17.0.2",
|
|
49
49
|
"asynciterator": "^3.4.2",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"browser": {
|
|
63
63
|
"./lib/index.js": "./lib/index-browser.js"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "1e88a2053c15d75cc2e93c5161abdb24a4346c3d"
|
|
66
66
|
}
|