4 months ago
I have a small project with a Postgres DB, a python app running in docker, and a react app running in docker. The database seems to be deployed properly and the backend shows successful deployment, but I cannot access the backend api. The backend logs show that there was success in deploying and running, but the system logs show:
Waiting for application startup.
Starting How Soon Timer API...
Environment: production
Version: 0.5.0
Database URL: postgresql://postgres:HLqhccCSeQDPmSirpUgdfnbTRwcFUqyN@postgres.railway.internal:5432/railway
CORS Origins: ['http://localhost:3000';, 'http://127.0.0.1:3000';, 'http://frontend-production-3a83.up.railway.app';]
Testing database connection...
Database connection check successful
Database connection successful
Loading wordlist...
Wordlist loaded: 7776 words
Possible combinations: 470,184,984,576
Application startup completed (some services may be degraded)
Application startup complete.
Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
Shutting down
Waiting for application shutdown.
Shutting down How Soon Timer API...
Application shutdown complete.
Finished server process [1].
I don't understand what is shutting down the backend. I don't see any error messages or other triggers in my code or logs.
Any ideas?
9 Replies
4 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
4 months ago
So it's getting shut down and not crashed ?
Does it happen immediately or some fixed or random time ?
4 months ago
As far as I can tell, it shuts down immediately after start up. It does not indicate it crashed, and trying to access it returns a 502.
It does not exhibit this behavior locally or when run on another hosting platform, so I do not think it is my code that is intentionally exiting.
slandspeople
As far as I can tell, it shuts down immediately after start up. It does not indicate it crashed, and trying to access it returns a 502.It does not exhibit this behavior locally or when run on another hosting platform, so I do not think it is my code that is intentionally exiting.
4 months ago
Can you provide the contents of DockerFile?
slandspeople
As far as I can tell, it shuts down immediately after start up. It does not indicate it crashed, and trying to access it returns a 502.It does not exhibit this behavior locally or when run on another hosting platform, so I do not think it is my code that is intentionally exiting.
4 months ago
What's the memory limit for this service ?
clashing
Can you provide the contents of DockerFile?
4 months ago
Dockerfile is
# Use Python 3.11 Alpine Linux base image
FROM python:3.11-alpine
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apk add --no-cache \
gcc \
musl-dev \
postgresql-dev \
postgresql-client \
libffi-dev
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Copy startup scripts
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh && \
chmod +x /app/start.py
# Create non-root user
RUN adduser -D -s /bin/sh appuser && \
chown -R appuser:appuser /app && \
chown appuser:appuser /entrypoint.sh
USER appuser
# Expose port (Railway will provide PORT env var)
EXPOSE 8000
# No HEALTHCHECK in Dockerfile - Railway handles this externally
# Run migrations then start server with Railway optimizations
CMD sh -c "alembic upgrade head && sleep 2 && exec uvicorn app.main:app --host 0.0.0.0 --port \${PORT:-8000} --log-level info --workers 1 --timeout-keep-alive 30"
smolpaw
What's the memory limit for this service ?
4 months ago
Overall plan is the hobby plan. I set the limits on the backend to 4 cores / 4 Gigs. It really shouldn't exceed that, it is a pretty simple python service.
4 months ago
Have you configured health checks for this service in railway dashboard ? if yes can you test it by removing them ?
4 months ago
You're going to bump into a lot of sharp edges that Railway doesn't make obvious if you don't read the docs.
I recommend you restructure your dockerfile a bit.
Create an entrypoint.sh in the same directory as your dockerfile and do something like this in it:
Notice: When not in "dev" mode uvicorn will serve on ipv6 -- this is a requirement for your service to be reachable on Railway's internal network (https://docs.railway.com/guides/private-networking#python--uvicorn)
Then in your dockerfile:
Next, make sure you have set the PORT env variable within railway for your service configuration -- Railway doesn't auto-detect this.
And finally most importantly..
Your dockerfile exposes PORT 8000,
BUT your Uvicorn logs from the first message show its on Port 8080 make sure these are aligned! (It's probably just this that's the real problem, but if you don't use ipv6 you'll bump into that next)
One or all of these things should probably fix you up. I can't recommend changing your "CMD" in your dockerfile enough.. it's pretty brittle. Hope this helps!