Skip to content

feat(client): handle timeout in SSE link - #6214

Merged
KATT merged 32 commits into
nextfrom
11-10-timeout-inact
Nov 13, 2024
Merged

KATT merged 32 commits into
nextfrom
11-10-timeout-inact

Conversation

@KATT

@KATT KATT commented Nov 10, 2024 •

Copy link
Copy Markdown
Member

Closes #

🎯 Changes

Adds ability to timeout an SSE connection without losing tracked events.

From testing, browsers seem really bad at keeping track of a server that e.g. gets killed.

Should I add a default maybe?

Thinking something like default timeout 30s, default ping every 15s

@KATT KATT added the 🚧 wip work in progress label Nov 10, 2024
@railway-app

railway-app Bot commented Nov 10, 2024 •

Copy link
Copy Markdown

πŸš… Deployed to the trpc-pr-6214 environment in trpc-sse-and-websockets

Service Status Web Updated (UTC)
next-prisma-websockets-starter ◻️ Removed (View Logs) Nov 13, 2024 at 10:52 pm

@vercel

vercel Bot commented Nov 10, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-prisma-starter βœ… Ready (Inspect) Visit Preview Nov 13, 2024 10:50pm
og-image βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 13, 2024 10:50pm
www βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 13, 2024 10:50pm

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2024 •

Copy link
Copy Markdown

Open in Stackblitz

pnpm add https://pkg.pr.new/trpc/trpc/@trpc/client@6214
pnpm add https://pkg.pr.new/trpc/trpc/@trpc/next@6214
pnpm add https://pkg.pr.new/trpc/trpc/@trpc/react-query@6214
pnpm add https://pkg.pr.new/trpc/trpc/@trpc/server@6214

commit: 250c4d1

EventSource: EventSourceLike.AnyConstructor;
}

async function withTimeout<T>(opts: {

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.

Would this be better as its own link maybe? timeoutLink feels like a useful primitive and might simplify things?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since it seems to be an issue with all browsers I kinda want it built-in

It's enough to do kill -9 on a server for EventSource to hang in Chrome

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.

Fair, MR looks great, happy to approve whenever you say its ready

const result = await promise;

if (value.done) {
// console.debug('result', result, 'done', result.done);

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.

a dead log

});
```

When configuring both client timeout and server ping, ensure that:

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.

could this be a validation step at runtime?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

tricky tbh

# Conflicts:
#	packages/server/src/adapters/node-http/nodeHTTPRequestHandler.ts
#	packages/server/src/unstable-core-do-not-import/stream/utils/withPing.ts
@github-actions

Copy link
Copy Markdown
Contributor

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.

This branch was successfully deployed

5 active deployments
Preview – www β€” 250c4d1f Deployed Nov 13, 2024 by vercel[bot]
Preview – trpc-next-app-dir β€” 250c4d1f Deployed Nov 13, 2024 by vercel[bot]
Preview – next-prisma-starter β€” 250c4d1f Deployed Nov 13, 2024 by vercel[bot]
Preview – examples-todomvc β€” 250c4d1f Deployed Nov 13, 2024 by vercel[bot]
Preview – og-image β€” 250c4d1f Deployed Nov 13, 2024 by vercel[bot]
trpc-pr-6214 β€” 250c4d1f Deployed Nov 13, 2024 by railway-app[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants