Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- changed: Remove NYM mixFetch per-host request queue now that `@nymproject/mix-fetch` handles concurrency natively.

## 2.43.1 (2026-02-23)

- changed: Upgrade `@nymproject/mix-fetch` to improve performance with new concurrency changes.
Expand Down
1 change: 0 additions & 1 deletion src/io/browser/browser-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function makeBrowserIo(logBackend: LogBackend): EdgeIo {
if (privacy === 'nym') {
// Ensure mixFetch is initialized before use
await initMixFetch(log)
// Use queued fetch to handle mixFetch's one-request-per-host limitation
return await queueMixFetch(uri, {
...opts,
mode: 'unsafe-ignore-cors' as RequestMode
Expand Down
1 change: 0 additions & 1 deletion src/io/react-native/react-native-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ async function makeIo(logBackend: LogBackend): Promise<EdgeIo> {
if (privacy === 'nym') {
// Ensure mixFetch is initialized before use
await initMixFetch(log)
// Use queued fetch to handle mixFetch's one-request-per-host limitation
const response = await queueMixFetch(uri, {
...opts,
mode: 'unsafe-ignore-cors' as RequestMode
Expand Down
42 changes: 2 additions & 40 deletions src/util/nym.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,6 @@ export const mixFetchOptions: SetupMixFetchOps = {
// MixFetch initialization state
let mixFetchInitPromise: Promise<IMixFetch> | null = null

// Per-host request queue to handle mixFetch's one-request-per-host limitation
// Maps host -> Promise that resolves when current request completes (for chaining)
const hostRequestChains = new Map<string, Promise<Response>>()

/**
* Extract the host:port from a URI for queue keying
*/
function getHostKey(uri: string): string {
try {
const url = new URL(uri)
const port =
url.port !== '' ? url.port : url.protocol === 'https:' ? '443' : '80'
return `${url.hostname}:${port}`
} catch {
return uri
}
}

/**
* Initialize the NYM mixFetch client. Must be called before using mixFetch.
* Safe to call multiple times - subsequent calls return the same promise.
Expand All @@ -58,31 +40,11 @@ export async function initMixFetch(log: EdgeLog): Promise<IMixFetch> {
}

/**
* Queue-wrapped mixFetch that serializes requests per host.
* mixFetch only allows one concurrent request per host, so we chain them.
* Thin wrapper around mixFetch with pre-configured options.
*/
export async function queueMixFetch(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need queueMixFetch at all. We can just inline mixFetch where queueMixFetch is being invoked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed on the current branch. queueMixFetch has been removed (commit cb91393) and mixFetch is now called directly where the queue was previously invoked: src/io/browser/browser-io.ts:55 and src/io/react-native/react-native-worker.ts:182 (commit d8b74e0). src/util/nym.ts no longer exports a queue wrapper, only initMixFetch/mixFetchOptions. Leaving the thread unresolved for the PR author to close.

uri: string,
opts: RequestInit & { mode?: string }
): Promise<Response> {
const hostKey = getHostKey(uri)

// Get the current chain for this host (or resolved promise if none)
const previousChain = hostRequestChains.get(hostKey) ?? Promise.resolve()

// Chain our request after the previous one
const ourWork = previousChain
.catch(() => {}) // Ignore errors from previous request
.then(async () => await mixFetch(uri, opts, mixFetchOptions))
.finally(() => {
// Clean up if we're still the chain tail
if (hostRequestChains.get(hostKey) === ourWork) {
hostRequestChains.delete(hostKey)
}
})

// Store our chain BEFORE awaiting - ensures subsequent requests wait for us
hostRequestChains.set(hostKey, ourWork)

return await ourWork
return await mixFetch(uri, opts, mixFetchOptions)
}