Request failed: Application error

Hello, my app was working perfectly for 2 months, and today API keeps returning error code, only redeployment is helping. be16331c-c1f2-481b-ab18-12bfc74c9ff9
35 Replies
Percy
Percy2y ago
Project ID: be16331c-c1f2-481b-ab18-12bfc74c9ff9
Brody
Brody2y ago
could you please share your repo?
akku铁木
akku铁木OP2y ago
I am using socket.io, and at one specific moment, all sockets were disconnected: Socket disconnected transport error Socket disconnected transport error And mongodb server connection was lost: MongooseServerSelectionError: connection timed out at Function.Model.$wrapCallback (/app/node_modules/mongoose/lib/model.js:5195:32) at /app/node_modules/mongoose/lib/query.js:4901:21 at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:41:5 at new Promise (<anonymous>) at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:40:10) at model.Query.exec (/app/node_modules/mongoose/lib/query.js:4900:10) at model.Query.Query.then (/app/node_modules/mongoose/lib/query.js:4983:15) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) { reason: TopologyDescription { type: 'Single', servers: Map(1) { 'containers-us-west-159.railway.app:7849' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, setName: null, maxElectionId: null, maxSetVersion: null, commonWireVersion: 0, logicalSessionTimeoutMinutes: null }, code: undefined }
Brody
Brody2y ago
you can't connect to your app over any other external port other than 443 it shows there that you're trying to connect to port 7849, that's the internal port, and not accessible externally, use 443 aka no port with the https scheme
akku铁木
akku铁木OP2y ago
But why it was working all the time?
Brody
Brody2y ago
it would have never worked if you where trying to connect to port 7849 externally, I can promise you that
akku铁木
akku铁木OP2y ago
For example, after redeployment, it is working right now
Brody
Brody2y ago
repo please
akku铁木
akku铁木OP2y ago
But I am sure, after 1-2 hours it will crash again
Brody
Brody2y ago
bruh I can't read, I'm so sorry that's the address for the database I'm really sorry
akku铁木
akku铁木OP2y ago
Repo is private, can you send me your email so I can add you?
akku铁木
akku铁木OP2y ago
Added
Brody
Brody2y ago
have you recently upgraded to dev plan?
akku铁木
akku铁木OP2y ago
Yes
Brody
Brody2y ago
how recently?
akku铁木
akku铁木OP2y ago
Jan 27, 2023
Brody
Brody2y ago
that's not recently
akku铁木
akku铁木OP2y ago
Oh Is it a problem with some rate limits?
Brody
Brody2y ago
I look at repo soon, am on mobile right now and reviewing code on mobile is not fun
akku铁木
akku铁木OP2y ago
Ok
Brody
Brody2y ago
are you using a railway provided mongodb?
akku铁木
akku铁木OP2y ago
Yes
Brody
Brody2y ago
you are using process.env.DATABASE_URL in the mongoose connection function, but you want to be using process.env.MONGO_URL please remove DATABASE_URL from your service variables and then setup the correct variable references with their default names, then use process.env.MONGO_URL in db.js https://docs.railway.app/develop/variables#reference-variables
akku铁木
akku铁木OP2y ago
One sec Done
Brody
Brody2y ago
show me a screenshot of your service variables please
akku铁木
akku铁木OP2y ago
akku铁木
akku铁木OP2y ago
My socket io server uses 8065 port, and I included PORT variable to 8065 in service variables
Brody
Brody2y ago
you can remove PORT from those variables, railway will then inject its own auto generated PORT and then you can just have your code listen on process.env.PORT also dont run your app with nodemon on railway
akku铁木
akku铁木OP2y ago
Can be these problems the reason of application error?
Brody
Brody2y ago
this could be this and this, are just improvements
akku铁木
akku铁木OP2y ago
Ok, thank you very much I will definitely let you know the progress
Brody
Brody2y ago
do those two improvements i mentioned too 🙂
akku铁木
akku铁木OP2y ago
I read every letter of your messages twice, so I'll definitely do
Brody
Brody2y ago
love to hear it!
"scripts": {
"start": "node api/index.js",
"dev": "nodemon api/index.js"
},
"scripts": {
"start": "node api/index.js",
"dev": "nodemon api/index.js"
},
do this then you wont need to define any custom start commands in the service settings
Want results from more Discord servers?
Add your server