fix: guard the connect-time listen failure on the refresh generation
Copilot review: `openModernListenStreamOnConnect`'s catch reconciled unconditionally, unlike the subscribe/unsubscribe call sites. The `connect` event is dispatched before the stream opens, so a listener subscribing to a resource can start and acknowledge a newer refresh while this one is still awaiting its `listen()` — and reconciling anyway would arm a reconnect that tears down a healthy stream. Apply the same generation test. Also consolidates the tests' private-member access onto the file's existing `internals()` helper (one justified double cast, hoisted and documented) and makes the failure stub bump the generation the way the real method does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HDdo1rNRVQnVRRdsqSrvG3
This commit is contained in:
parent
0325d81493
commit
eda8ec0db8
1 changed files with 80 additions and 34 deletions
|
|
@ -4981,9 +4981,17 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
* every request-scoped feature works without this stream. It is reported the
|
||||
* way a lost stream is — hand it to the reconnect machinery, which retries
|
||||
* with backoff and settles on `"ended"` past the cap.
|
||||
*
|
||||
* Gated on the same generation test as `subscribeToResource` — see the long
|
||||
* comment there. This call is *not* the only refresh that can be in flight:
|
||||
* the `connect` event has already been dispatched, so a listener subscribing
|
||||
* to a resource can start and acknowledge a newer refresh while this one is
|
||||
* still awaiting its `listen()`. Reconciling unconditionally would then arm a
|
||||
* reconnect that tears down a stream that is up and healthy.
|
||||
*/
|
||||
private async openModernListenStreamOnConnect(): Promise<void> {
|
||||
if (!this.isModernEra() || !this.wantsModernStream()) return;
|
||||
const generationBefore = this.modernListenGeneration;
|
||||
try {
|
||||
await this.refreshModernSubscription();
|
||||
} catch (error) {
|
||||
|
|
@ -4991,7 +4999,9 @@ export class InspectorClient extends InspectorClientEventTarget {
|
|||
{ error },
|
||||
"Failed to open the modern subscriptions/listen stream on connect",
|
||||
);
|
||||
this.reconcileModernStreamStateAfterFailedRefresh();
|
||||
if (this.modernListenGeneration === generationBefore + 1) {
|
||||
this.reconcileModernStreamStateAfterFailedRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue