Skip to content

Commit 3af36fa

Browse files
committed
fix(ssh): 丢弃失效运行记录后复用同目录服务
- 运行记录的进程检查失败时,清除整条记录以继续查找同目录服务。 - 扩展启动脚本回归测试,验证复用存活服务且不重新启动。 - 变更范围检查通过,72 项测试通过,4 项 Linux 专属用例在 macOS 跳过。
1 parent ad7fd46 commit 3af36fa

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎packages/ssh/src/tunnel.test.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ switch (args[1]) {
288288
);
289289
yield* fs.writeFileString(
290290
path.join(directory, "ps"),
291-
'#!/bin/sh\nif [ "$T3_FIXTURE_ZOMBIE" = "1" ]; then printf Z; else exec /bin/ps "$@"; fi\n',
291+
'#!/bin/sh\nfor arg do pid="$arg"; done\nif [ -n "$T3_FIXTURE_ZOMBIE_PID" ] && [ "$pid" = "$T3_FIXTURE_ZOMBIE_PID" ]; then printf Z; else exec /bin/ps "$@"; fi\n',
292292
{ mode: 0o700 },
293293
);
294-
let zombie = "0";
294+
let zombiePid = "";
295295
let readyPort = "41773";
296296
const localSsh = ChildProcessSpawner.make((command) => {
297297
assert.strictEqual(command._tag, "StandardCommand");
@@ -302,7 +302,7 @@ switch (args[1]) {
302302
env: {
303303
HOME: directory,
304304
PATH: `${directory}:/usr/bin:/bin`,
305-
T3_FIXTURE_ZOMBIE: zombie,
305+
T3_FIXTURE_ZOMBIE_PID: zombiePid,
306306
T3CODE_HOME: customHome,
307307
T3_FIXTURE_READY_PORT: readyPort,
308308
T3_FIXTURE_STATE_DIR: stateDir,
@@ -343,14 +343,37 @@ switch (args[1]) {
343343
yield* fs.readFileString(path.join(stateDir, "run-t3.sh")),
344344
"old runner stays intact",
345345
);
346-
zombie = "1";
346+
zombiePid = String(external.pid);
347347
readyPort = "41774";
348348
assert.deepEqual(yield* launch, { remotePort: 41774, remoteServerKind: "managed" });
349349
assert.strictEqual(
350350
(yield* fs.readFileString(path.join(stateDir, "server-home"))).trim(),
351351
customHome,
352352
);
353353
assert.isTrue(yield* external.isRunning);
354+
355+
// A rejected runtime PID must not hide a live sibling on the selected home.
356+
const sibling = yield* realSpawner.spawn(
357+
ChildProcess.make(process.execPath, [
358+
"-e",
359+
"process.stdin.resume()",
360+
"--",
361+
"serve",
362+
"--host",
363+
"127.0.0.1",
364+
"--port",
365+
"41775",
366+
]),
367+
);
368+
const siblingDir = path.join(directory, ".t3/ssh-launch", "sibling");
369+
yield* fs.makeDirectory(siblingDir, { recursive: true });
370+
yield* fs.writeFileString(path.join(siblingDir, "managed"), "managed");
371+
yield* fs.writeFileString(path.join(siblingDir, "pid"), String(sibling.pid));
372+
yield* fs.writeFileString(path.join(siblingDir, "port"), "41775");
373+
yield* fs.writeFileString(path.join(siblingDir, "server-home"), customHome);
374+
readyPort = "41775";
375+
assert.deepEqual(yield* launch, { remotePort: 41775, remoteServerKind: "external" });
376+
assert.isTrue(yield* sibling.isRunning);
354377
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
355378
);
356379

‎packages/ssh/src/tunnel.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ if [ -n "$DEFAULT_RUNTIME_INFO" ]; then
737737
DEFAULT_RUNTIME_PID="\${DEFAULT_RUNTIME_INFO%% *}"
738738
DEFAULT_REMOTE_PORT="\${DEFAULT_RUNTIME_INFO#* }"
739739
if ! server_running "$DEFAULT_RUNTIME_PID"; then
740+
DEFAULT_RUNTIME_INFO=""
740741
DEFAULT_RUNTIME_PID=""
741742
DEFAULT_REMOTE_PORT=""
742743
fi

0 commit comments

Comments
 (0)