R
Railway•3mo ago
raf

Abort signal on SSE not working

So I've been rewriting my polling code with Server-sent-events (SSE) to reduce egress fees to railway, and on the server side I've add a abort signal listener to stop the running interval. (I'm using NextJS App directory) here's the code
request.signal.addEventListener("abort", async () => {
console.info("Client disconnected");
clearInterval(interval);
await closeStream();
});
request.signal.addEventListener("abort", async () => {
console.info("Client disconnected");
clearInterval(interval);
await closeStream();
});
On my local computer and on other VPS, it works fine, when the client is closing the EventSource, the server received abort signal directly. However on Railway, the server cannot get the abort signal, and another bug that I found is that SSE connection only can works for around 2 minutes before the server automatically close the connection. Please keep in mind that in another machine everything works normally and there's no connection duration limit, it only happens on Railway. So I suspect that it has to do with Railway Edge Proxy, can anyone clarify and possibly help me with the solution to this problem? Thanks!
41 Replies
Percy
Percy•3mo ago
Project ID: 2fee4431-767f-456a-8835-06cdd70005f7
raf
raf•3mo ago
2fee4431-767f-456a-8835-06cdd70005f7
raf
raf•3mo ago
Even in the Railway SSE POC, the connection is closed after around 5 minutes, no EventStream coming from network tab after the error is shown POC Url: https://utilities.up.railway.app/sse
No description
raf
raf•3mo ago
So after reading the docs, it seems that my suspicion is true, railway edge network only support max duration of 5 minutes for http request But still idk why the abort signal not received by the server
No description
Brody
Brody•3mo ago
the docs are correct, there is indeed a max duration of 5 minutes, and that is not something that can be or will be changed. but the abort signal not being received is interesting, I'll have to look into that.
raf
raf•3mo ago
yeah i've the workaround for the 5 minute limit issue, it's fine for that, but not with the abort signal one
Brody
Brody•3mo ago
have you tried listening for a close event?
raf
raf•3mo ago
well seems that nextjs doesn't provide that, and also this is the example sent by the vercel team itself https://github.com/vercel/next.js/discussions/48427#discussioncomment-5624604
GitHub
Server-Sent Events don't work in Next API routes · vercel next.js ·...
Bug report Describe the bug When using Next's API routes, chunks that are written with res.write aren't sent until after res.end() is called. To Reproduce Steps to reproduce the behavior, p...
Brody
Brody•3mo ago
so what happens when your client closes the event source? nothing happens?
raf
raf•3mo ago
in nextjs, it seems that close event are on abort signal, and on abort, i will log it and also clear the running interval as the written code in this thread however, the abort signal is not called when i deployed on railway been trying to disable/enable the edge proxy but the results stay same
raf
raf•3mo ago
GitHub
Server-Sent Events don't work in Next API routes · vercel next.js ·...
Bug report Describe the bug When using Next's API routes, chunks that are written with res.write aren't sent until after res.end() is called. To Reproduce Steps to reproduce the behavior, p...
Brody
Brody•3mo ago
are you aware that disabling / enabling the edge proxy takes several minutes to take effect?
raf
raf•3mo ago
yes i've waited for around 10-15 minutes after enabling/disabling, still no effect
raf
raf•3mo ago
(Picture 1) so the expected result is, between this 2 "New connection established" there should be "Client disconnected" log since i open a tab -> close it -> then open it again (Picture 2) however, as you can see, the "Client disconnected" log is not showing between that log, however it does shown late and disconnected together after several time
No description
No description
angelo
angelo•3mo ago
are you using the railway provided domain?
Want results from more Discord servers?
Add your server