Skip to content

Commit 1d06b8c

Browse files
committed
RDBC-908 Handle undici imports in createAgent more robustly to avoid issues in certain environments
1 parent ff50e35 commit 1d06b8c

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Http/RequestExecutor.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,28 @@ export class RequestExecutor implements IDisposable {
378378
}
379379
}
380380

381-
private static async createAgent(options: Agent.Options) {
381+
private static async createAgent(options: Agent.Options) {
382+
try {
383+
let AgentInstance;
384+
382385
try {
383-
const { Agent: AgentInstance } = await import(importFix("undici"));
384-
return new AgentInstance(options);
386+
const undiciModule = await import(importFix("undici"));
387+
AgentInstance = undiciModule.Agent;
385388
} catch (err) {
386-
// If we can't import undici - we might be in cloudflare env - simply return no-agent.
387-
return null;
389+
const undiciModule = await import("undici");
390+
AgentInstance = undiciModule.Agent;
391+
}
392+
393+
if (!AgentInstance) {
394+
throw new Error("Agent not found in undici module");
388395
}
396+
397+
return new AgentInstance(options);
398+
} catch (err) {
399+
// If we can't import undici - we might be in cloudflare env - simply return no-agent.
400+
return null;
389401
}
402+
}
390403

391404
public getTopologyNodes(): ServerNode[] {
392405
const topology = this.getTopology();

0 commit comments

Comments
 (0)