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
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
Project ID:
2fee4431-767f-456a-8835-06cdd70005f7
2fee4431-767f-456a-8835-06cdd70005f7
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](https://cdn.answeroverflow.com/1260165666498019399/image.png)
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](https://cdn.answeroverflow.com/1260167394479964243/image.png)
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.
yeah i've the workaround for the 5 minute limit issue, it's fine for that, but not with the abort signal one
have you tried listening for a close event?
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...
so what happens when your client closes the event source? nothing happens?
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
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...
are you aware that disabling / enabling the edge proxy takes several minutes to take effect?
yes
i've waited for around 10-15 minutes after enabling/disabling, still no effect
(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](https://cdn.answeroverflow.com/1260301670265655336/image.png)
![No description](https://cdn.answeroverflow.com/1260301670647332916/image.png)
are you using the railway provided domain?