@comunica/actor-init-query 2.2.2-alpha.20.0 → 2.3.1-alpha.22.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.
@@ -138,8 +138,14 @@ class HttpServiceSparqlEndpoint {
138
138
  // Respawn crashed workers
139
139
  worker.once('exit', (code, signal) => {
140
140
  if (!worker.exitedAfterDisconnect) {
141
- stderr.write(`Worker ${worker.process.pid} died with ${code || signal}. Starting new worker.\n`);
142
- cluster.fork();
141
+ if (code === 9 || signal === 'SIGKILL') {
142
+ stderr.write(`Worker ${worker.process.pid} forcefully killed with ${code || signal}. Killing main process as well.\n`);
143
+ cluster.disconnect();
144
+ }
145
+ else {
146
+ stderr.write(`Worker ${worker.process.pid} died with ${code || signal}. Starting new worker.\n`);
147
+ cluster.fork();
148
+ }
143
149
  }
144
150
  });
145
151
  // Handle worker timeouts
@@ -147,9 +153,9 @@ class HttpServiceSparqlEndpoint {
147
153
  worker.on('message', ({ type, queryId }) => {
148
154
  if (type === 'start') {
149
155
  workerTimeouts[queryId] = setTimeout(() => {
150
- stderr.write(`Worker ${worker.process.pid} timed out for query ${queryId}.\n`);
151
156
  try {
152
157
  if (worker.isConnected()) {
158
+ stderr.write(`Worker ${worker.process.pid} timed out for query ${queryId}.\n`);
153
159
  worker.send('shutdown');
154
160
  }
155
161
  }
@@ -206,10 +212,22 @@ class HttpServiceSparqlEndpoint {
206
212
  await new Promise(resolve => connection.end('!TIMEDOUT!', resolve));
207
213
  }
208
214
  // Kill the worker once the connections have been closed
209
- // eslint-disable-next-line unicorn/no-process-exit
210
215
  process.exit(15);
211
216
  }
212
217
  });
218
+ // Catch global errors, and cleanly close open connections
219
+ process.on('uncaughtException', async (error) => {
220
+ stderr.write(`Terminating worker ${process.pid} with ${openConnections.size} open connections due to uncaught exception.\n`);
221
+ stderr.write(error.stack);
222
+ // Stop new connections from being accepted
223
+ server.close();
224
+ // Close all open connections
225
+ for (const connection of openConnections) {
226
+ await new Promise(resolve => connection.end('!ERROR!', resolve));
227
+ }
228
+ // Kill the worker once the connections have been closed
229
+ process.exit(15);
230
+ });
213
231
  }
214
232
  /**
215
233
  * Handles an HTTP request.
@@ -335,7 +353,9 @@ class HttpServiceSparqlEndpoint {
335
353
  const { data } = await engine.resultToString(result, mediaType);
336
354
  data.on('error', (error) => {
337
355
  stdout.write(`[500] Server error in results: ${error.message} \n`);
338
- response.end('An internal server error occurred.\n');
356
+ if (!response.writableEnded) {
357
+ response.end('An internal server error occurred.\n');
358
+ }
339
359
  });
340
360
  data.pipe(response);
341
361
  eventEmitter = data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-init-query",
3
- "version": "2.2.2-alpha.20.0",
3
+ "version": "2.3.1-alpha.22.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.2.2-alpha.20.0",
35
- "@comunica/bus-context-preprocess": "2.2.2-alpha.20.0",
36
- "@comunica/bus-http-invalidate": "2.2.2-alpha.20.0",
37
- "@comunica/bus-init": "2.2.2-alpha.20.0",
38
- "@comunica/bus-optimize-query-operation": "2.2.2-alpha.20.0",
39
- "@comunica/bus-query-operation": "2.2.2-alpha.20.0",
40
- "@comunica/bus-query-parse": "2.2.2-alpha.20.0",
41
- "@comunica/bus-query-result-serialize": "2.2.2-alpha.20.0",
42
- "@comunica/context-entries": "2.2.2-alpha.20.0",
43
- "@comunica/core": "2.2.2-alpha.20.0",
44
- "@comunica/logger-pretty": "2.2.2-alpha.20.0",
45
- "@comunica/runner": "2.2.2-alpha.20.0",
46
- "@comunica/types": "2.2.2-alpha.20.0",
34
+ "@comunica/actor-http-proxy": "2.3.1-alpha.22.0",
35
+ "@comunica/bus-context-preprocess": "2.3.1-alpha.22.0",
36
+ "@comunica/bus-http-invalidate": "2.3.1-alpha.22.0",
37
+ "@comunica/bus-init": "2.3.1-alpha.22.0",
38
+ "@comunica/bus-optimize-query-operation": "2.3.1-alpha.22.0",
39
+ "@comunica/bus-query-operation": "2.3.1-alpha.22.0",
40
+ "@comunica/bus-query-parse": "2.3.1-alpha.22.0",
41
+ "@comunica/bus-query-result-serialize": "2.3.1-alpha.22.0",
42
+ "@comunica/context-entries": "2.3.1-alpha.22.0",
43
+ "@comunica/core": "2.3.1-alpha.22.0",
44
+ "@comunica/logger-pretty": "2.3.1-alpha.22.0",
45
+ "@comunica/runner": "2.3.1-alpha.22.0",
46
+ "@comunica/types": "2.3.1-alpha.22.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": "cde1c9148ae06ad0878515d011601daebb659665"
65
+ "gitHead": "300afb0d1e324dff121acd0fbd24b4eb37e201f5"
66
66
  }