Avoid dev TrackerHub poll gateway timeouts

This commit is contained in:
2026-05-07 00:20:13 +03:00
parent 6a3c8f2558
commit eadd42cacc
+32 -6
View File
@@ -224,6 +224,8 @@ export function _resetSharedConnections(): void {
// ---- Default builder (dynamic import) ----
const DEV_TRACKER_LONG_POLL_TIMEOUT_MS = 10000;
export function _shouldUseLongPollingForDevTrackerProxy(url: string): boolean {
try {
const parsed = new URL(url, "http://localhost");
@@ -241,15 +243,39 @@ async function defaultBuildConnection(
url: string,
delays: number[],
): Promise<HubConnectionLike> {
const { HubConnectionBuilder, HttpTransportType, LogLevel } = await import(
"@microsoft/signalr"
);
const {
DefaultHttpClient,
HttpClient,
HubConnectionBuilder,
HttpTransportType,
LogLevel,
NullLogger,
} = await import("@microsoft/signalr");
const builder = new HubConnectionBuilder();
const withUrlOptions = _shouldUseLongPollingForDevTrackerProxy(url)
? { transport: HttpTransportType.LongPolling }
const useDevTrackerLongPolling = _shouldUseLongPollingForDevTrackerProxy(url);
const withUrlOptions = useDevTrackerLongPolling
? {
transport: HttpTransportType.LongPolling,
httpClient: new (class extends HttpClient {
private readonly inner = new DefaultHttpClient(NullLogger.instance);
send(request: Parameters<InstanceType<typeof HttpClient>["send"]>[0]) {
if (request.method !== "GET") {
return this.inner.send(request);
}
return this.inner.send({
...request,
timeout: DEV_TRACKER_LONG_POLL_TIMEOUT_MS,
});
}
})(),
}
: undefined;
return (withUrlOptions ? builder.withUrl(url, withUrlOptions) : builder.withUrl(url))
return (withUrlOptions
? builder.withUrl(url, withUrlOptions)
: builder.withUrl(url))
.withAutomaticReconnect(delays)
// Suppress SignalR's internal console logging. The hub is optional
// (failures degrade to polling) and we already handle status via