You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then I created another Nuxt project to be the client that will connect to the SSE endpoint (using a Nitro proxy route). The connection works and event stream works too. 👍🏻
The problem is that when I turn off the server (manually cause an error), I get an error in the console in SSE server but on the client the eventSource.onerror doesn't receive any error event (!). This prevents me from being able to attempt a reconnect on the client. It seems the Nitro proxy does not forward the error to the client and hangs in an active state that is broken. The client still thinks the connection is active but in reality it is not.
Run pnpm install && pnpm dev - this should start the project on port 3001
Open http://localhost:3001 and you should see messages coming in from SSE server app. (if the ports are 3000 and 3001)
Now go over to the terminal that is running the SSE Server project and stop the dev server.
Now go over to the terminal that is running the SSE Client project and you will see this error:
ERROR [nuxt] [request error] [unhandled] [500] terminated
at Fetch.onAborted (node:internal/deps/undici/undici:10916:53)
at Fetch.emit (node:events:518:28)
at Fetch.terminate (node:internal/deps/undici/undici:10102:14)
at Object.onError (node:internal/deps/undici/undici:11034:38)
at _Request.onError (node:internal/deps/undici/undici:7200:31)
at errorRequest (node:internal/deps/undici/undici:9765:17)
at Socket.onSocketClose (node:internal/deps/undici/undici:8927:9)
at Socket.emit (node:events:518:28)
at TCP.<anonymous> (node:net:337:12)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
It says that this is unhandled error but there is no way to handle this error. I tried adding a try...catch in server/routes/sse.ts but it does not work.
The main problem though is that this code does not trigger this client code:
// This does not work with Nuxt/Nitro proxy :(// onerror never gets called (!)eventSource.onerror=(event)=>{console.error('EventSource failed:',event)// We should attempt to reconnect here}
The client does not receive a onerror event. And this is a big problem because if I don't know there is a problem I can't attempt a reconnect or notify the user that something is wrong with the backend server.
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered:
Environment
Reproduction
SSE server: https://github.com/martinszeltins/nitro-sse-server
SSE client: https://github.com/martinszeltins/nuxt-sse-client-with-proxy
Describe the bug
As @danielroe suggested, I am creating this issue here in Nitro repo.
Here is the issue:
I created an SSE (Server-sent Events) server using Nuxt with the help of @atinux gist here: https://gist.github.com/Atinux/05836469acca9649fa2b9e865df898a2. Thanks @atinux!
Then I created another Nuxt project to be the client that will connect to the SSE endpoint (using a Nitro proxy route). The connection works and event stream works too. 👍🏻
The problem is that when I turn off the server (manually cause an error), I get an error in the console in SSE server but on the client the
eventSource.onerror
doesn't receive any error event (!). This prevents me from being able to attempt a reconnect on the client. It seems the Nitro proxy does not forward the error to the client and hangs in an active state that is broken. The client still thinks the connection is active but in reality it is not.How to reproduct the issue:
pnpm install && pnpm dev
- this should start the project on port 3000pnpm install && pnpm dev
- this should start the project on port 3001http://localhost:3001
and you should see messages coming in from SSE server app. (if the ports are 3000 and 3001)It says that this is
unhandled
error but there is no way to handle this error. I tried adding atry...catch
inserver/routes/sse.ts
but it does not work.The main problem though is that this code does not trigger this client code:
The client does not receive a
onerror
event. And this is a big problem because if I don't know there is a problem I can't attempt a reconnect or notify the user that something is wrong with the backend server.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: