# ECS task stopped with exit code 139 (segmentation fault)

AWS error fixes · Updated 16 November 2026

**Short answer:** Exit code 139 means the process was killed by SIGSEGV (128 + 11): it read or wrote memory it wasn't allowed to. In containers on ECS this almost always comes from native code: a compiled dependency built for a different C library or CPU, a buggy native extension, or a thread running out of stack. Get a stack trace from the crashing process, then rebuild or replace the native component.

## What it means

```
Stopped reason: Essential container in task exited
Containers: app  exitCode: 139
```

Unlike exit 1, your application didn't decide to exit; the kernel killed it for an illegal memory access. Managed languages (Python, Node.js, Java, Go) don't segfault from ordinary code bugs, so look for whatever native code is running: C extensions, image and PDF libraries, database drivers, JVM or runtime bugs, or binaries copied into the image.

The last log lines before the crash show what the app was doing. Often nothing useful is logged, because the process dies instantly without unwinding.

## Common causes

| Cause | Clue |
|---|---|
| Binary or wheel built for glibc running on an Alpine (musl) image, or the reverse | Crashes at import or first use of a library; works in a Debian-based image |
| Native module compiled on a developer machine and copied in | `node_modules` or a virtualenv copied from macOS or a different distro |
| Bug in a native dependency version | Started after a dependency upgrade; crashes on specific inputs |
| Stack exhaustion in a thread with a small stack | Deep recursion or large stack buffers; often on musl, whose default thread stack is small |
| Emulated architecture mismatch | Image built for one CPU via emulation and run on another; mixed-arch layers |

## Get a stack trace

- **Python:** set `PYTHONFAULTHANDLER=1` in the container's environment. On a segfault, Python prints the stack of every thread to stderr, which goes to your log driver.

- **Node.js:** start with `node --report-on-fatalerror`; for native crashes a crash-handler module that prints a native backtrace is often more useful.

- **Java:** the JVM writes an `hs_err_pid*.log` file; point it at stdout or a mounted volume with `-XX:ErrorFile` so it survives the task.

- **Reproduce locally** with the exact image and architecture:

  ```
  docker run --rm --platform linux/amd64 \
    -e PYTHONFAULTHANDLER=1 123456789012.dkr.ecr.eu-west-2.amazonaws.com/app:v42
  ```

Check which architecture the task runs on and which the image provides:

```
aws ecs describe-task-definition --task-definition app \
  --query 'taskDefinition.runtimePlatform'
docker manifest inspect 123456789012.dkr.ecr.eu-west-2.amazonaws.com/app:v42 | grep architecture
```

## Fix it

1. **Install native dependencies inside the image build**, never by copying them from the host, and add `node_modules` or `.venv` to `.dockerignore`.
2. **Match the base image to the binaries.** If a library ships glibc builds only, use a Debian or Ubuntu based image instead of Alpine.
3. **Pin or roll back** the native dependency that changed, then report the crash upstream with the stack trace.
4. **Increase the thread stack size** if the trace shows deep recursion (for example `-Xss` for Java, or the threading library's stack size setting).
5. **Roll the service back** to the previous task definition revision while you investigate, if the crash came with a deploy.

## Questions

### What does exit code 139 mean in a Docker container?

The main process was terminated by signal 11 (SIGSEGV), a segmentation fault caused by an invalid memory access, almost always in native code.

### Can a memory limit cause exit code 139?

Not directly. Hitting the container's memory limit produces an OOM kill with exit code 137. A 139 points to a crash inside the process.

### Why does my container segfault only on ECS and not locally?

The ECS task often runs on a different CPU architecture or with a different image build than your laptop. Reproduce with the exact image digest and --platform set to the task's architecture.

## When this happens away from your desk

Segfaults tend to appear as tasks restarting in a loop, which shows up as service events and failing health checks. CloudConsole, a phone app for AWS, is built to show those events and the last log lines on your phone so you can decide whether to roll back.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Amazon ECS stopped task error codes](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/stopped-task-error-codes.html)
- [Amazon ECS documentation](https://docs.aws.amazon.com/ecs/)

## Related

- [Essential container in task exited](https://cloudconsole.dev/errors/ecs-essential-container-exited)
- [ECS task stopped: Essential container exited with exit code 137](https://cloudconsole.dev/errors/ecs-exit-code-137)
- [ECS task stopped: Essential container in task exited with exit code 1](https://cloudconsole.dev/errors/ecs-exit-code-1)
- [aws ecs describe-task-definition](https://cloudconsole.dev/cli/ecs-describe-task-definition)
- [aws ecs update-service](https://cloudconsole.dev/cli/ecs-update-service)
- [CannotPullContainerError: pull image manifest has been retried](https://cloudconsole.dev/errors/ecs-cannotpullcontainererror)

---

Source: https://cloudconsole.dev/errors/ecs-exit-code-139

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
