also looking at this
[DO NOT MERGE] diag: #2267 CLI-hang discriminator
#2269
5 files
+370
-6
| @@ -22,6 +22,7 @@ import * as path from 'node:path' | ||
| 22 | 22 | import * as process from 'node:process' |
| 23 | 23 | import { mergeGatewayFragments, readGatewayFragments, resolveGatewayOptions, startGateway } from '../src/gateway' |
| 24 | 24 | import * as Start from '../src/start' |
| 25 | import { envDump, jsFields, parentDump, procDump, runSweep, say } from './helpers/spawn-diag' | |
| 25 | 26 | |
| 26 | 27 | const CERTS_DIR = '/etc/rpx/certs' |
| 27 | 28 | |
| @@ -353,9 +354,16 @@ async function freePort(): Promise<number> { | ||
| 353 | 354 | return port |
| 354 | 355 | } |
| 355 | 356 | |
| 356 | const CLI_STARTS = process.platform !== 'linux' | |
| 357 | ||
| 358 | describe.skipIf(!CLI_STARTS)('rpx gateway (CLI, end to end)', () => { | |
| 357 | /** | |
| 358 | * #2267 diagnostic, in situ. The Linux skip is lifted on this branch so the | |
| 359 | * baseline runs exactly where the hang was recorded — this file is position 23 | |
| 360 | * of 48 in bun's deterministic order, and the same shape passes from a | |
| 361 | * standalone file at position 38. On a hang the child's and this parent's | |
| 362 | * /proc state is dumped before the kill, then the variant sweep runs from the | |
| 363 | * same spot. The long-lived case stays skipped on Linux: it is not the | |
| 364 | * discriminator and would only add 45s. | |
| 365 | */ | |
| 366 | describe('rpx gateway (CLI, end to end)', () => { | |
| 359 | 367 | it('starts and prints its help', async () => { |
| 360 | 368 | const cli = path.join(import.meta.dir, '..', 'bin', 'cli.ts') |
| 361 | 369 | const child = spawn(process.execPath, [cli, '--help'], { stdio: ['ignore', 'pipe', 'pipe'] }) |
| @@ -368,13 +376,33 @@ describe.skipIf(!CLI_STARTS)('rpx gateway (CLI, end to end)', () => { | ||
| 368 | 376 | new Promise<string>(resolve => setTimeout(() => resolve('still running after 45s'), 45_000)), |
| 369 | 377 | ]) |
| 370 | 378 | |
| 371 | if (child.exitCode === null && child.signalCode === null) | |
| 372 | child.kill('SIGKILL') | |
| 379 | // Trigger on the race, not on exitCode/signalCode: last run the dud | |
| 380 | // ChildProcess reported a non-null one at 45s with no exit event and no | |
| 381 | // bytes, which took the wrong branch and skipped the dump. | |
| 382 | if (exit.startsWith('still running')) { | |
| 383 | say('IN-SITU BASELINE HUNG at gateway.test.ts') | |
| 384 | say(` ${jsFields(child)}`) | |
| 385 | say(` child:\n ${child.pid ? procDump(child.pid) : '(no pid)'}`) | |
| 386 | say(` parent:\n ${parentDump()}`) | |
| 387 | try { | |
| 388 | child.kill('SIGKILL') | |
| 389 | } | |
| 390 | catch {} | |
| 391 | } | |
| 392 | else { | |
| 393 | say('IN-SITU BASELINE OK:', exit, `${output.length} bytes`) | |
| 394 | } | |
| 373 | 395 | |
| 374 | 396 | expect(output, `rpx --help produced nothing (${exit})`).toContain('gateway') |
| 375 | 397 | }, 60_000) |
| 376 | 398 | |
| 377 | it('serves a fragment\'s route over plain HTTP with --no-https on the given port', async () => { | |
| 399 | it('[2267-diag] in-situ spawn variant sweep', async () => { | |
| 400 | envDump() | |
| 401 | const results = await runSweep(path.join(import.meta.dir, '..', 'bin', 'cli.ts'), 'in-situ') | |
| 402 | expect(results).toHaveLength(8) | |
| 403 | }, 200_000) | |
| 404 | ||
| 405 | it.skipIf(process.platform === 'linux')('serves a fragment\'s route over plain HTTP with --no-https on the given port', async () => { | |
| 378 | 406 | const upstream = Bun.serve({ port: 0, hostname: '127.0.0.1', fetch: req => new Response(`gateway-upstream ${req.headers.get('x-forwarded-host')}`) }) |
| 379 | 407 | const httpPort = await freePort() |
| 380 | 408 | // Two routes so the fragment looks like a real box (and the shared |