4 months ago
Project ID: e109d868-4850-42f1-b29e-ee2473509479
Hi Railway Support,
We are experiencing a persistent SIGTERM error 502 when deploying our Next.js application and would appreciate your assistance in diagnosing the issue.
Application Details:
* Framework: Next.js (v15.3.2)
* Language: TypeScript
* Database: MongoDB (User will specify if using Railway's MongoDB or external Atlas)
* Build Process: Standard npm run build
(which is next build
)
* Start Command:npm run start
(which executes next start -H 0.0.0.0 -p 8080
)
We understand Railway injects a PORT
environment variable, and we are prepared to change this to next start -p $PORT
if recommended.
Problem Description:
The application builds successfully locally and also appears to build successfully on Railway according to the build logs. However, shortly after deployment, the service becomes unhealthy and we encounter a SIGTERM error (often manifesting as a 502 Bad Gateway to end-users). This happens consistently.
Troubleshooting Steps Taken:
1. Successful Local Builds: The application consistently builds successfully on our local development machines using npm run build
.
2. Verified Start Command: Our package.json
script for start
is next start -H 0.0.0.0 -p 8080
. The railway.json
uses npm run start
as the startCommand
.
```json
// railway.json
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"numReplicas": 1,
"startCommand": "npm run start",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
```
3. Environment Variables: We have configured the following essential environment variables in the Railway service dashboard:
* MONGO_URI
: Connection string for our MongoDB instance.
4. Health Check Endpoint: We have a basic health check endpoint at /api/health
that returns a 200 OK.
```typescript
// src/app/api/health/route.ts
import { NextResponse } from 'next/server';
export async function GET() {
return NextResponse.json({ status: 'ok', timestamp: new Date().toISOString() });
}
```
5. Dependency Management: We have ensured all dependencies are correctly listed in package.json
and have recently reinstalled node_modules
from scratch.
6. Resource Allocation (Initial Check): We are on the [User to fill in their Railway plan, e.g., Hobby/Pro] plan. We haven't seen explicit out-of-memory errors in our application logs on Railway, but we are unsure if this could be a factor.
Could you please help us by:
1. Inspecting Platform Logs: Reviewing any internal platform logs for our service that might provide more details about the SIGTERM signal or the reason for the service becoming unhealthy (e.g., resource exhaustion, specific crash details not visible in application logs, health check failures from Railway's perspective).
2. Verifying Health Check Behavior: Confirming if Railway's health checks are passing for our application and, if not, what the specific failure reason is.
3. Start Command/Port: Advising if our current start command (`next start -H 0.0.0.0 -p 8080`) is optimal or if we should switch to next start -p $PORT
or another configuration.
4. Any Other Insights: Providing any other insights or recommendations based on common issues seen with Next.js deployments on Railway.
We have a DEPLOYMENT.md
guide that we've been following, and we believe the basic setup aligns with Next.js deployment best practices.
Please let us know what further information you require from our end.
Thank you for your time and assistance.
0 Replies
4 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 4 months ago
Status changed to Solved eenvywithin • 4 months ago