Repository navigation
fix(client): wire the operation AbortSignal in the WebSocket link - #7434
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
On-demand reviews are free for the next 8 days. After that, they cost $0.25 per reviewed file. Or wait 45 minutes for your next included review. View limit detailsLimit details: Youβve used all 10 included reviews currently available. Review configuration: βοΈ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: π Files selected for processing (1)
π WalkthroughWalkthroughWebSocket requests now register an ChangesWebSocket abort handling
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant AbortController
participant WsClient
participant ServerSubscription
AbortController->>WsClient: abort signal
WsClient->>WsClient: complete observer and run teardown
WsClient->>ServerSubscription: stop subscription
ServerSubscription-->>WsClient: remove server:msg listener
Possibly related issues
Possibly related PRs
Suggested reviewers: π₯ Pre-merge checks | β 5β Passed checks (5 passed)
β¨ Finishing Touchesπ§ͺ Generate unit tests (beta)
Comment |
@trpc/client
@trpc/next
@trpc/openapi
@trpc/react-query
@trpc/server
@trpc/tanstack-react-query
@trpc/upgrade
commit: |
There was a problem hiding this comment.
π§Ή Nitpick comments (1)
packages/tests/server/websockets.test.ts (1)
297-304: π Maintainability & Code Quality | π΅ Trivial | π€ Low valueType the mock explicitly and simplify the callback.
As per coding guidelines: "Use proper TypeScript typing for mocks". Provide the explicit signature to
vi.fn()to improve type safety. You can also pass the mock directly to the callback to simplify the code.β»οΈ Proposed refactor
- const onStartedMock = vi.fn(); + const onStartedMock = vi.fn<() => void>(); ctx.client.onMessageObservable.subscribe(undefined, { signal: ac.signal, - onStarted() { - onStartedMock(); - }, + onStarted: onStartedMock, });π€ Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/tests/server/websockets.test.ts` around lines 297 - 304, Update onStartedMock in the websocket subscription test to use an explicit vi.fn signature matching the onStarted callback, then pass the mock directly as the callback instead of wrapping it in an onStarted function.Source: Coding guidelines
π€ Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/tests/server/websockets.test.ts`:
- Around line 297-304: Update onStartedMock in the websocket subscription test
to use an explicit vi.fn signature matching the onStarted callback, then pass
the mock directly as the callback instead of wrapping it in an onStarted
function.
βΉοΈ Review info
βοΈ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1d974282-9d3f-4d98-b768-5d734ed67a06
π Files selected for processing (2)
packages/client/src/links/wsLink/wsClient/wsClient.tspackages/tests/server/websockets.test.ts
|
Just a heads-up in case it's helpful: the failing |
e9e7fbf to
e6f3903
Compare
The wsLink request observable removed an `abort` listener that was never added, so aborting an operation's signal never tore the request down: the subscription kept running and its server-side listener leaked. Add an `abort` listener that completes the observer (running the existing teardown, which sends `subscription.stop`), and remove the matching listener on cleanup. Fixes trpc#7431
Use an explicit vi.fn signature and pass onStarted directly in the abort-signal subscription test.
c0b0666 to
37d8480
Compare
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Closes #7431
π― Changes
The WebSocket link's
requestobservable never listened to the operation'sAbortSignal. Its teardown calledsignal?.removeEventListener('abort', abort), but nothing ever registered that listener βabortwas the function returned bybatchSend, not a listener. Aborting an operation's signal did nothing: the request was never torn down, the subscription kept running, and its server-side listener leaked.Register an
abortlistener that completes the observer. Completing runs the existing teardown, which sendssubscription.stopfor subscriptions, so an aborted operation now ends cleanly. The matching listener is removed on teardown, and an already-aborted signal is handled synchronously.β Checklist
Summary by CodeRabbit
Bug Fixes
Tests