fix(network): apply connection timeout in server and extension hosts
Complete the runtime entrypoints from #3404 without changing address-family selection.
This commit is contained in:
@@ -190,6 +190,14 @@ Reachable filesystem routes: `api:fs:read` (attachments), `api:fs:search`
|
||||
Maintenance: reviews, changelog entries, and parity claims consult this map;
|
||||
whoever mounts or unmounts a surface updates it in the same change.
|
||||
|
||||
## Network connections
|
||||
|
||||
Extension activation applies `networkDefaults.ts` before registering handlers.
|
||||
It gives Node connection attempts 5 seconds, matching the web runtime, so quota
|
||||
requests to distant providers can connect. This is an extension-host process
|
||||
default, including other Node connections in that host. Address-family selection
|
||||
stays unchanged; runtimes without the setter retain their existing behavior.
|
||||
|
||||
## Global OpenCode paths
|
||||
|
||||
`opencodeConfigPaths.ts` owns the global config directory for config CRUD,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { startGlobalEventWatcher, stopGlobalEventWatcher, setChatViewProvider }
|
||||
import { pathsEqualWithNormalizedDriveLetter } from './pathUtils';
|
||||
import { resolveWorkspaceFolders } from './workspaceResolver';
|
||||
import { InlineCommentThreads, SIDEBAR_SURFACE_ID } from './InlineCommentThreads';
|
||||
import { applyConnectAttemptTimeout } from './networkDefaults';
|
||||
|
||||
let chatViewProvider: ChatViewProvider | undefined;
|
||||
|
||||
@@ -52,6 +53,7 @@ const formatDurationMs = (value: number | null | undefined) => {
|
||||
};
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
applyConnectAttemptTimeout();
|
||||
outputChannel = vscode.window.createOutputChannel('OpenChamber');
|
||||
|
||||
let moveToRightSidebarScheduled = false;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as net from 'node:net';
|
||||
import { applyConnectAttemptTimeout } from './networkDefaults';
|
||||
|
||||
test('allows slow connections without changing address-family selection', () => {
|
||||
const previousTimeout = net.getDefaultAutoSelectFamilyAttemptTimeout();
|
||||
const previousFamily = net.getDefaultAutoSelectFamily();
|
||||
try {
|
||||
net.setDefaultAutoSelectFamilyAttemptTimeout(250);
|
||||
assert.equal(applyConnectAttemptTimeout(), true);
|
||||
assert.equal(net.getDefaultAutoSelectFamilyAttemptTimeout(), 5_000);
|
||||
assert.equal(net.getDefaultAutoSelectFamily(), previousFamily);
|
||||
} finally {
|
||||
net.setDefaultAutoSelectFamilyAttemptTimeout(previousTimeout);
|
||||
}
|
||||
});
|
||||
|
||||
test('unsupported runtimes retain their existing behavior', () => {
|
||||
assert.equal(applyConnectAttemptTimeout({}), false);
|
||||
assert.equal(applyConnectAttemptTimeout({
|
||||
setDefaultAutoSelectFamilyAttemptTimeout() { throw new Error('unsupported'); },
|
||||
}), false);
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as net from 'node:net';
|
||||
|
||||
// Mirrors the web runtime policy for distant quota endpoints. The extension
|
||||
// host has its own Node fetch stack and does not inherit server defaults.
|
||||
export function applyConnectAttemptTimeout(
|
||||
netModule: Partial<Pick<typeof net, 'setDefaultAutoSelectFamilyAttemptTimeout'>> = net,
|
||||
): boolean {
|
||||
try {
|
||||
if (!netModule.setDefaultAutoSelectFamilyAttemptTimeout) return false;
|
||||
netModule.setDefaultAutoSelectFamilyAttemptTimeout(5_000);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user