Skip to content

Troubleshooting guide

500 Internal Server Error: how to find the cause

A 500 is your application saying "something went wrong and I did not handle it". The answer is almost always an exception you can find in seconds with the right tooling.

3 min read9 sectionsUpdated

On this page

Key points

  • 500 is a generic application failure, usually an unhandled exception.
  • Never show stack traces to users; log them with context instead.
  • Group errors into issues so one bug is one item, not thousands of log lines.
  • Most 500s arrive with a deploy or a data change.

Usual causes

  • Unhandled exceptions: null references, type errors, unexpected input.
  • Database errors: failed migrations, constraint violations, connection limits.
  • Configuration: a missing environment variable or secret after a deploy.
  • Dependency failures that the code does not handle: a timeout from a payment API bubbling up as an exception.
  • Permissions: the app cannot read a file or write to a directory.
  • Resource limits: out of memory, too many open files.

Finding the exception

  1. Get the time, route and request ID. Good error pages show a request ID the user can quote.
  2. Search logs for that request ID or for ERROR-level lines on that route in that minute.
  3. Open the trace. The failing span carries the exception type, message and stack trace.
  4. Check the error group: is this new since the last release, or old and rising?
bash
# Plain logs on a server
journalctl -u myapp --since "15 min ago" | grep -iE 'error|exception|traceback' | tail -n 40

# Docker
docker logs --since 15m myapp 2>&1 | grep -iE 'error|exception' | tail -n 40

# Kubernetes (including the previous container if it crashed)
kubectl logs deploy/myapp --since=15m | grep -iE 'error|exception' | tail -n 40
kubectl logs <pod> --previous | tail -n 40

Handle errors deliberately

Not every failure should be a 500. Return the right code so clients and monitoring can react properly:

SituationBetter response
Invalid input400 or 422 with a clear message
Not signed in / not allowed401 / 403
Resource missing404
Dependency down, try later503 with Retry-After
Dependency too slow504 from the gateway, or a fast fallback
Genuine bug500, logged with stack trace and request ID

Preventing repeats

  • Error tracking that groups exceptions into issues with counts, first and last seen, affected endpoints and versions. In VitalRix error tracking, issues can be assigned, resolved, and come back as regressed if they reappear.
  • Alert on error rate, not on single errors, per service or endpoint.
  • Deploy markers and canary releases, so a bad release is spotted on a small share of traffic. See canary deployments.
  • Startup checks that fail fast when required configuration is missing, instead of throwing on the first request.

Frequently asked questions

How do I see the error behind a 500?

Check the application logs or your error tracker for that time and route. If your service is traced, the failing span holds the exception and stack trace.

Is a 500 bad for SEO?

Occasional 500s are not a problem. Persistent 500s on a page can lead search engines to drop it. Monitor important pages so you hear about it first.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.