Merge a4cccc2231 into da71eaebd2
This commit is contained in:
commit
b8d102e0d5
1
openclaw
Submodule
1
openclaw
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 0639c7bf1f37bafeb847afc9e422f05f3bb084a3
|
||||
@ -10,8 +10,9 @@ export async function writeOAuthCredentials(
|
||||
agentDir?: string,
|
||||
): Promise<void> {
|
||||
// Write to resolved agent dir so gateway finds credentials on startup.
|
||||
const emailStr = typeof creds.email === "string" ? creds.email : "default";
|
||||
upsertAuthProfile({
|
||||
profileId: `${provider}:${creds.email ?? "default"}`,
|
||||
profileId: `${provider}:${emailStr}`,
|
||||
credential: {
|
||||
type: "oauth",
|
||||
provider,
|
||||
|
||||
@ -148,6 +148,19 @@ export async function startGatewayServer(
|
||||
port = 18789,
|
||||
opts: GatewayServerOptions = {},
|
||||
): Promise<GatewayServer> {
|
||||
// Install global unhandled rejection handler to prevent gateway crashes
|
||||
// from background promises (e.g., Telegram polling, network operations)
|
||||
const handleUnhandledRejection = (reason: unknown, _promise: Promise<unknown>) => {
|
||||
const formatted = reason instanceof Error ? reason.message : String(reason);
|
||||
log.error(`unhandled promise rejection: ${formatted}`);
|
||||
// Log additional details for debugging
|
||||
if (reason instanceof Error && reason.stack) {
|
||||
log.debug(`rejection stack: ${reason.stack}`);
|
||||
}
|
||||
// Don't crash the gateway - log and continue
|
||||
};
|
||||
process.on("unhandledRejection", handleUnhandledRejection);
|
||||
|
||||
// Ensure all default port derivations (browser/canvas) see the actual runtime port.
|
||||
process.env.OPENCLAW_GATEWAY_PORT = String(port);
|
||||
logAcceptedEnvOption({
|
||||
@ -572,6 +585,9 @@ export async function startGatewayServer(
|
||||
|
||||
return {
|
||||
close: async (opts) => {
|
||||
// Remove unhandled rejection handler on shutdown
|
||||
process.off("unhandledRejection", handleUnhandledRejection);
|
||||
|
||||
if (diagnosticsEnabled) {
|
||||
stopDiagnosticHeartbeat();
|
||||
}
|
||||
|
||||
@ -161,7 +161,12 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
|
||||
const runner = run(bot, createTelegramRunnerOptions(cfg));
|
||||
const stopOnAbort = () => {
|
||||
if (opts.abortSignal?.aborted) {
|
||||
void runner.stop();
|
||||
// Properly await runner.stop() to prevent unhandled rejections
|
||||
runner.stop().catch((err) => {
|
||||
(opts.runtime?.error ?? console.error)(
|
||||
`telegram: runner stop failed: ${formatErrorMessage(err)}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
};
|
||||
opts.abortSignal?.addEventListener("abort", stopOnAbort, { once: true });
|
||||
@ -194,6 +199,13 @@ export async function monitorTelegramProvider(opts: MonitorTelegramOpts = {}) {
|
||||
}
|
||||
} finally {
|
||||
opts.abortSignal?.removeEventListener("abort", stopOnAbort);
|
||||
// Ensure runner is stopped to prevent lingering promises
|
||||
try {
|
||||
await runner.stop();
|
||||
} catch {
|
||||
// Suppress errors from runner.stop() in finally block
|
||||
// (already logged by stopOnAbort if abort-triggered)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user