fix(gateway): respond before writing config in skills.update to prevent connection abort

When enabling/disabling a skill via the Web UI, the skills.update RPC method
would write the config file before sending the response. This caused the
config file watcher to trigger a gateway restart (SIGUSR1) before the HTTP
response could be sent to the client, resulting in connection abort errors.

This change ensures the response is sent first by using setImmediate() to
defer the config file write until after the response has been delivered.

Fixes issue where skills toggle in Web UI would cause:
- Unhandled promise rejection: AbortError: This operation was aborted
- Gateway crash with "Failed running 'dist/entry.js gateway --force'"
This commit is contained in:
九灵云 2026-01-27 16:04:10 +08:00
parent 2ad550abe8
commit 565a81562e

View File

@ -176,7 +176,14 @@ export const skillsHandlers: GatewayRequestHandlers = {
...cfg,
skills,
};
await writeConfigFile(nextConfig);
// Respond first to ensure the client receives the response before any gateway restart
respond(true, { ok: true, skillKey: p.skillKey, config: current }, undefined);
// Write config asynchronously after responding to avoid aborting the response
// when the config file watcher triggers a gateway restart (SIGUSR1)
setImmediate(() => {
writeConfigFile(nextConfig).catch(() => {
// Config write errors are logged elsewhere; catch here to prevent unhandled rejection
});
});
},
};