Bad Request Error

a-bmt02
PRO

5 months ago

Occationally I get the Error below in my Railway server for When some of my users are accessing the the server. I've been trying to debug what the problem is but i can't.

BadRequestError: request aborted

at IncomingMessage.onAborted (/app/node_modules/raw-body/index.js:245:10)

at IncomingMessage.emit (node:events:517:28)

at IncomingMessage._destroy (node:_http_incoming:224:10)

at _destroy (node:internal/streams/destroy:109:10)

at IncomingMessage.destroy (node:internal/streams/destroy:71:5)

at abortIncoming (node:_http_server:781:9)

at socketOnClose (node:_http_server:775:3)

at Socket.emit (node:events:529:35)

at TCP. (node:net:350:12)
Solved

0 Replies

a-bmt02
PRO

5 months ago

N/A


a-bmt02
PRO

5 months ago

My Usage Seems Fine , I'm on the Pro Plan

1337925574844354600


5 months ago

tell me more about the server you run on railway


a-bmt02
PRO

5 months ago

It takes in a bunch of images and audio file and uses ffmpeg to convert the images and audios into one video file


5 months ago

what's the tech stack


a-bmt02
PRO

5 months ago

the server is NodeJs and the Client is NextJs


5 months ago

how many replicas do you currently have


a-bmt02
PRO

5 months ago

Just one


a-bmt02
PRO

5 months ago

It works fine on my end and other users have no issues too most of the times. But occationally the error pops up


5 months ago

try adding a few more replicas


a-bmt02
PRO

5 months ago

How many more would you suggest? And why does that solve the issue if you dont mind


5 months ago

start with 3 total,

a single node instance may not be able to handle all of the traffic.


a-bmt02
PRO

5 months ago

But shouldnt i see the resourses maxing out if thats the case?


5 months ago

a single node instance cannot use more than 1 vCPU since node is single threaded


a-bmt02
PRO

5 months ago

Fair. After adding the replicas do i need to change any code or the allocation will be automatic?


5 months ago

we will run 3 instances of your app and handle the routing, as long as you don't store user state in memory you should be fine


a-bmt02
PRO

5 months ago

You recommed i add 3 different locations or use a single one

1337933736141914400
1337933736414806000


5 months ago

that's up to you, do you have users from different locations?


5 months ago

wouldn't want to add replicas in locations you don't have any users


a-bmt02
PRO

5 months ago

I do have users from different locations. Mostly Us/Europe , but i'll experiment with both and compare


a-bmt02
PRO

5 months ago

If the issues persist i'll let you know


a-bmt02
PRO

5 months ago

Thank you!


5 months ago

sounds good!


a-bmt02
PRO

5 months ago

So i don't know if this issue is related


a-bmt02
PRO

5 months ago

But after turning on multiple replicas now , my server side events are not working


a-bmt02
PRO

5 months ago

Usually i have SSE set up so that the progress of the video generation is sent from the nodejs server to the client constantly. But now the SSE does not work at all after turning on mutiple replicas

1337945641887993900


a-bmt02
PRO

5 months ago

The server works fine and the video is generated successfully but the SSE updates does not show on the frontend. There is a browser error though

1337945989998317600


5 months ago

SSE does work with multi-region replicas, so this would be something with your code, what's the actual error? and are there errors in your deploy logs?


a-bmt02
PRO

5 months ago

I'm using single region replicas. This is the deploy logs

1337946628354478000


5 months ago

you have replicas in multiple regions


5 months ago

those are old deploy logs


a-bmt02
PRO

5 months ago

These are my replicas

1337947172355707000


a-bmt02
PRO

5 months ago

1337947252626296800


a-bmt02
PRO

5 months ago

My bad , there is no new deplog error logs


5 months ago

ah I was just going off of this, either way, SSE fundamentally works with a single region or multi region replicas


a-bmt02
PRO

5 months ago

In that case the issue might be something else. I'll debug. It might just be a coincedence that it started right after i added replicas


5 months ago

i would say that you are storing state in memory


5 months ago

the replica that is doing the ffmpeg stuff may not be the the replica that answered the SSE request


a-bmt02
PRO

5 months ago

I'm not sure if i am storing state in memory or not. I don't know what that exactly means , but i'm using SSE to track the progress and send to the client


5 months ago

yeah then you are doing ffmpeg stuff on one instance and another instance doesn't know about it so SSE fails, you need to store the progress of a ffmpeg job globally in redis so that all replicas have access to the state of any ffmpeg job


a-bmt02
PRO

5 months ago

Hmmm thank you for that!


5 months ago

it's just a guess from what you've told me, I could be wrong, please still do your own research


a-bmt02
PRO

5 months ago

I will. Thanks Brody


5 months ago

no problem!


5 months ago

!s


Status changed to Solved brody 5 months ago