mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Add timeout to invokeHook on plugins
This commit is contained in:
1 parent
fcdbf59f7a
commit
770e6a41d4
1 file changed
+11
-2
+11
-2
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const helpers = require("./helpers");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conceptual base for master and instance plugins.
|
* Conceptual base for master and instance plugins.
|
||||||
@@ -733,8 +734,16 @@ async function invokeHook(plugins, hook, ...args) {
|
|||||||
let results = [];
|
let results = [];
|
||||||
for (let [name, plugin] of plugins) {
|
for (let [name, plugin] of plugins) {
|
||||||
try {
|
try {
|
||||||
let result = await plugin[hook](...args);
|
// Use an object to detect if the hook failed on timeout or tried to return a value looking like an error
|
||||||
if (result !== undefined) {
|
const timeout = {};
|
||||||
|
let result = await helpers.timeout(
|
||||||
|
plugin[hook](...args),
|
||||||
|
15000,
|
||||||
|
timeout
|
||||||
|
);
|
||||||
|
if (result === timeout) {
|
||||||
|
throw new Error(`Invoking hook ${hook} timed out for plugin ${name}`);
|
||||||
|
} else if (result !== undefined) {
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in new issue
Block a user