Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dstack/kms/auth-eth-bun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ bun run check
- `ETH_CHAIN_ID` - reject every decision if the RPC reports a different chain ID (default: unset, no check)
- `ETH_FINALITY_CONFIRMATIONS` - read policy this many blocks behind the RPC head (default: 0, the head)

The Bun server sets `idleTimeout` to 255s (Bun's maximum). Bun's default of 10s closes the socket while a slow `eth_call` is still in flight, which surfaces on the KMS side as `connection closed before message completed`.

## API endpoints

### GET /
Expand Down
10 changes: 10 additions & 0 deletions dstack/kms/auth-eth-bun/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ beforeEach(() => {
mockGetBlockNumber.mockResolvedValue(100n);
});

describe('server runtime config', () => {
it('keeps Bun idleTimeout above the KMS webhook timeout', async () => {
// Vitest calls `fetch` directly and never hits Bun.serve, so this pins the
// config that production actually loads. Bun's default of 10s closes the
// socket while GET / is still awaiting eth_call.
const indexModule = await import('./index.ts');
expect(indexModule.default.idleTimeout).toBeGreaterThanOrEqual(60);
});
});

describe('API Compatibility Tests', () => {
describe('GET /', () => {
it('should return system info matching OpenAPI spec', async () => {
Expand Down
4 changes: 4 additions & 0 deletions dstack/kms/auth-eth-bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ app.post('/bootAuth/kms',
const port = parseInt(process.env.PORT || '3000');
console.log(`starting server on port ${port}`);

// Bun defaults idleTimeout to 10s and closes the socket while the handler is
// still awaiting eth_call. KMS's webhook timeout is 60s; stay above that so the
// client times out first. Bun's documented maximum is 255.
export default {
port,
idleTimeout: 255,
fetch: app.fetch,
};
3 changes: 3 additions & 0 deletions dstack/kms/auth-mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ const port = parseInt(process.env.PORT || '3000');
const policy = getPolicy();
console.log(`starting mock auth server on port ${port} (policy: ${policy})`);

// Bun defaults idleTimeout to 10s and closes the socket while a handler is
// still awaiting work. Stay above the KMS webhook timeout (60s). Bun max: 255.
export default {
port,
idleTimeout: 255,
fetch: app.fetch,
};
3 changes: 3 additions & 0 deletions dstack/kms/auth-simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ const defaultConfigPath = process.env.AUTH_CONFIG_PATH || './auth-config.json';
console.log(`starting auth-simple server on port ${port}`);
console.log(`config path: ${defaultConfigPath}`);

// Bun defaults idleTimeout to 10s and closes the socket while a handler is
// still awaiting work. Stay above the KMS webhook timeout (60s). Bun max: 255.
export default {
port,
idleTimeout: 255,
fetch: app.fetch,
};
Loading