mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 20:40:43 +00:00
process/supervisor: track pty stdin destroyed state
This commit is contained in:
@@ -65,6 +65,7 @@ export async function createPtyAdapter(params: {
|
|||||||
let waitPromise: Promise<{ code: number | null; signal: NodeJS.Signals | number | null }> | null =
|
let waitPromise: Promise<{ code: number | null; signal: NodeJS.Signals | number | null }> | null =
|
||||||
null;
|
null;
|
||||||
let forceKillWaitFallbackTimer: NodeJS.Timeout | null = null;
|
let forceKillWaitFallbackTimer: NodeJS.Timeout | null = null;
|
||||||
|
let stdinDestroyed = false;
|
||||||
|
|
||||||
const clearForceKillWaitFallback = () => {
|
const clearForceKillWaitFallback = () => {
|
||||||
if (!forceKillWaitFallbackTimer) {
|
if (!forceKillWaitFallbackTimer) {
|
||||||
@@ -104,8 +105,14 @@ export async function createPtyAdapter(params: {
|
|||||||
}) ?? null;
|
}) ?? null;
|
||||||
|
|
||||||
const stdin: ManagedRunStdin = {
|
const stdin: ManagedRunStdin = {
|
||||||
destroyed: false,
|
get destroyed() {
|
||||||
|
return stdinDestroyed;
|
||||||
|
},
|
||||||
write: (data, cb) => {
|
write: (data, cb) => {
|
||||||
|
if (stdinDestroyed) {
|
||||||
|
cb?.(new Error("stdin is not writable"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
pty.write(data);
|
pty.write(data);
|
||||||
cb?.(null);
|
cb?.(null);
|
||||||
@@ -114,7 +121,11 @@ export async function createPtyAdapter(params: {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
end: () => {
|
end: () => {
|
||||||
|
if (stdinDestroyed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
|
stdinDestroyed = true;
|
||||||
const eof = process.platform === "win32" ? "\x1a" : "\x04";
|
const eof = process.platform === "win32" ? "\x1a" : "\x04";
|
||||||
pty.write(eof);
|
pty.write(eof);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -183,6 +194,7 @@ export async function createPtyAdapter(params: {
|
|||||||
// ignore disposal errors
|
// ignore disposal errors
|
||||||
}
|
}
|
||||||
clearForceKillWaitFallback();
|
clearForceKillWaitFallback();
|
||||||
|
stdinDestroyed = true;
|
||||||
dataListener = null;
|
dataListener = null;
|
||||||
exitListener = null;
|
exitListener = null;
|
||||||
settleWait({ code: null, signal: null });
|
settleWait({ code: null, signal: null });
|
||||||
|
|||||||
Reference in New Issue
Block a user