[Bug] Merge interceptor does not terminate all batched subscribers
Before you submit this issue, have you checked the following options?
- This is a reproducible problem.
- I searched existing issues and found no matching report.
Affected packages and versions
@univerjs/network on dev at cfb245a2f (repository package version 1.0.2).
Reproduction link
The existing merge interceptor test fixture can reproduce this at the public MergeInterceptorFactory API. Add the following test inside its describe block (its imports already include HTTPRequest and MergeInterceptorFactory; import Subject from rxjs and HTTPEvent from ../../response):
const source = new Subject<HTTPEvent<unknown>>();
const next: HTTPHandlerFn = () => source;
const fetchCheck = vitest.fn().mockResolvedValueOnce(false).mockResolvedValueOnce(true);
const interceptor = MergeInterceptorFactory<string, unknown>({
isMatch: () => true,
getParamsFromRequest: (request) => request.url,
mergeParamsToRequest: (_list, request) => request,
}, { fetchCheck });
const firstError = vitest.fn();
const secondError = vitest.fn();
interceptor(new HTTPRequest('GET', '/first'), next).subscribe({ error: firstError });
interceptor(new HTTPRequest('GET', '/second'), next).subscribe({ error: secondError });
await Promise.resolve(); // both requests have joined one source subscription
source.error(new Error('request failed'));
expect(firstError).toHaveBeenCalledOnce(); // fails on dev: called 0 times
expect(secondError).toHaveBeenCalledOnce();In a fresh run with the same setup, subscribe using complete callbacks and call source.complete() instead of source.error(...). The first callback is likewise never called.
Expected behavior
A merged source error should reach every active request in its batch, with the same error value. Source completion should complete every active batched stream.
Actual behavior
Only the subscriber whose fetchCheck initiated the merged request receives error or complete. An earlier request can remain pending after network failure, and an earlier stream remains unterminated when the shared source completes. The response next path already distributes values to all batched subscribers.
Root cause and related work
In MergeInterceptorFactory, the shared source's terminal callbacks close over the single observer from the invocation that starts the batch, although currentHookList contains all its subscribers. #2749 introduced this interceptor and is merged. No open PR currently changes the interceptor or its test fixture.
System information
Reproduced in the repository's Vitest test environment on Windows. The reproduction uses only the network package and RxJS; it does not require a browser.
Source: dream-num/univer