R
Railwayβ€’16mo ago
guypy

NextJS Application Random Crash

Hey πŸ‘‹ I have a NextJS service running on Railway which suddenly crashed (there were no active users at that time so the app was idle). After a restart of the service, everything went back to normal. On the deploy logs I see a SIGTERM signal (see below), I'm not sure though if it's there because of the restart attempts. 1. If the crash wasn't because of the SIGTERM, how can I investigate this more thoroughly? 2. If the crash was because of the SIGTERM - why did that happen, and how can I prevent it or at least make sure Railway automatically restarts the service? Thanks!
> client-app@0.0.1 start
> next start
ready - started server on 0.0.0.0:4200, url: http://localhost:4200
npm ERR! path /app/dist/apps/client-app
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- next start
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-03-15T09_43_22_663Z-debug-0.log
npm WARN config production Use `--omit=dev` instead.
> client-app@0.0.1 start
> next start
ready - started server on 0.0.0.0:4200, url: http://localhost:4200
npm ERR! path /app/dist/apps/client-app
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- next start
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-03-19T00_29_49_514Z-debug-0.log
> client-app@0.0.1 start
> next start
ready - started server on 0.0.0.0:4200, url: http://localhost:4200
npm ERR! path /app/dist/apps/client-app
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- next start
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-03-15T09_43_22_663Z-debug-0.log
npm WARN config production Use `--omit=dev` instead.
> client-app@0.0.1 start
> next start
ready - started server on 0.0.0.0:4200, url: http://localhost:4200
npm ERR! path /app/dist/apps/client-app
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- next start
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-03-19T00_29_49_514Z-debug-0.log
31 Replies
Percy
Percyβ€’16mo ago
Project ID: 4c244bec-c9dc-4d97-b44d-c09dcf0b97d3
Percy
Percyβ€’16mo ago
⚠️ experimental feature
guypy
guypyβ€’16mo ago
4c244bec-c9dc-4d97-b44d-c09dcf0b97d3
Brody
Brodyβ€’16mo ago
could you link your discord to railway please?
guypy
guypyβ€’16mo ago
Sure, linked it
Brody
Brodyβ€’16mo ago
where you on the trial plan at the time?
guypy
guypyβ€’16mo ago
No, haven't been on trial for about 2 months I think
guypy
guypyβ€’16mo ago
This happened again today, restarting the service didn't help, but a redeploy seemed to fix the issue for now. Any ideas? @Brody
Brody
Brodyβ€’16mo ago
#πŸ›‚ο½œreadme #5
guypy
guypyβ€’16mo ago
oops sorry, won't happen again. Would appreciate any help on this issue πŸ™
Brody
Brodyβ€’16mo ago
send your repo please and show me what your metrics look like during these crashes
guypy
guypyβ€’16mo ago
In the 2nd image you can see the downtimes, started around 03:30am IDT, ended after I redeployed the serviced at 07:30am. The metrics seem stable πŸ˜•
guypy
guypyβ€’16mo ago
The Github repo is private unfortunately, is there anything specific I could share that might be helpful?
Brody
Brodyβ€’16mo ago
package.json how much traffic does this site get?
guypy
guypyβ€’16mo ago
It's a monorepo, so this package.json is shared between all the services i have on the project
guypy
guypyβ€’16mo ago
Not much traffic at all, we're still on a closed beta around the time the crashes started I see there was no activity at all
Brody
Brodyβ€’16mo ago
could you send the nx.json?
guypy
guypyβ€’16mo ago
{
"npmScope": "cubic",
"affected": {
"defaultBase": "main"
},
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": [
"build",
"lint",
"test",
"e2e"
]
}
}
},
"generators": {
"@nrwl/react": {
"application": {
"babel": true
}
},
"@nrwl/next": {
"application": {
"style": "@emotion/styled",
"linter": "eslint"
}
}
},
"defaultProject": "client-app",
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"targetDefaults": {
"build": {
"dependsOn": [
"^build"
],
"inputs": [
"production",
"^production"
]
},
"e2e": {
"inputs": [
"default",
"^production"
]
},
"test": {
"inputs": [
"default",
"^production",
"{workspaceRoot}/jest.preset.js"
]
},
"lint": {
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json"
]
}
},
"namedInputs": {
"default": [
"{projectRoot}/**/*",
"sharedGlobals"
],
"sharedGlobals": [
"{workspaceRoot}/babel.config.json"
],
"production": [
"default",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json"
]
}
}
{
"npmScope": "cubic",
"affected": {
"defaultBase": "main"
},
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": [
"build",
"lint",
"test",
"e2e"
]
}
}
},
"generators": {
"@nrwl/react": {
"application": {
"babel": true
}
},
"@nrwl/next": {
"application": {
"style": "@emotion/styled",
"linter": "eslint"
}
}
},
"defaultProject": "client-app",
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"targetDefaults": {
"build": {
"dependsOn": [
"^build"
],
"inputs": [
"production",
"^production"
]
},
"e2e": {
"inputs": [
"default",
"^production"
]
},
"test": {
"inputs": [
"default",
"^production",
"{workspaceRoot}/jest.preset.js"
]
},
"lint": {
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json"
]
}
},
"namedInputs": {
"default": [
"{projectRoot}/**/*",
"sharedGlobals"
],
"sharedGlobals": [
"{workspaceRoot}/babel.config.json"
],
"production": [
"default",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/.eslintrc.json"
]
}
}
Brody
Brodyβ€’16mo ago
is the front-end a csr app?
guypy
guypyβ€’16mo ago
Nope, SSR
Brody
Brodyβ€’16mo ago
could you send me whatever config file is used to setup nx serve?
guypy
guypyβ€’16mo ago
This is for one application, the others are pretty much the same
Brody
Brodyβ€’16mo ago
it seems you have your app serving in dev mode https://nx.dev/packages/next#serving-next.js-applications
guypy
guypyβ€’16mo ago
I'm sure that the apps are running in production mode, in the screenshots you can see that on the development env the buildId is development and on production there's some random hash
guypy
guypyβ€’16mo ago
guypy
guypyβ€’16mo ago
Can you share maybe what is the meaning of a service getting SIGTERM on Railway? That might help me find the root cause here in case its applicative
Brody
Brodyβ€’16mo ago
the app might be getting build as prod, but the server isn't running as prod, please check the link I sent and apply that flag you also have Doppler set to dev, that's unwanted too
guypy
guypyβ€’16mo ago
OK, I'll make sure that the apps are running in full prod mode. Thanks! What would cause a service to get a SIGTERM though?
Brody
Brodyβ€’16mo ago
that sigterm likely isn't coming from railways container manager so my running guess is some unexpected side effect of running your server in dev mode
guypy
guypyβ€’16mo ago
Ok, I'll do some testing and see how it goes.. Hopefully you're right 🀞 Thanks for the help!
Brody
Brodyβ€’16mo ago
happy to help, I hope you get it sorted also, generally a bonus side effect of not running a dev server is less ram usage