-
-
Notifications
You must be signed in to change notification settings - Fork 783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server Fn Signal and API route (request.signal) does not actually fire 'abort' event. #3490
Comments
I think your server function example is incorrect. When running, I see In this example, throwing an error from the signal handler causes the node process to crash. Instead, you should synchronize the signal's event handler with the function execution, e.g. as shown in the docs: https://tanstack.com/start/latest/docs/framework/react/server-functions#cancellation I did not try the API route example, but I suspect it has the same issue. |
I'm sorry, but I'm not recieving To be clear, on the client, it will show ABORTED and update, but on the server terminal the
Doesn't the docs say that you can throw errors? import { createServerFn } from '@tanstack/start'
export const doStuff = createServerFn({ method: 'GET' }).handler(async () => {
throw new Error('Something went wrong!')
})
// Usage
function Test() {
try {
await doStuff()
} catch (error) {
console.error(error)
// {
// message: "Something went wrong!",
// stack: "Error: Something went wrong!\n at doStuff (file:///path/to/file.ts:3:3)"
// }
}
} Nevertheless, I've made changes so that its using I've made the updates in |
So it seems that signal works as expected for |
Which project does this relate to?
Start
Describe the bug
When canceling a server function or fetch to API Route, either by
abortController.abort()
or by refreshing / closing the tab to disconnect. The signal's 'abort' event is actually never fired on the server side.I've made a minimal reproduction here:
https://github.com/cpakken/start-signal-issue
On the terminal (server), it should console.log for 'abort' signal, but the server function will just continue its work. For computationally heavy server functions, you could use this abort event to trip a flag so that it stops any processing mid way through. Or if you pass the abort signal to a fetch called from the server, it never actually cancels it.
This might have to do with H3 Fetch and the way it implements aborts or detects when connection is closed abruptly?
Heres implementation from the minimal reproduction:
I've been using this as my abort signal, but ideally the request.signal or signal passed in from createServerFn should just work
Your Example Website or App
https://github.com/cpakken/start-signal-issue
Steps to Reproduce the Bug or Issue
https://github.com/cpakken/start-signal-issue
npm run dev
orbun dev
Click 'fetch' button and 'abort'
Click 'fetch' button and refresh the tab to disconnect
Expected behavior
In the terminal running Start, you should see the abort event triggering
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: