Blog
Segmentation fault + docker + gdb
The following scenario happened to me twice after upgrading the Symfony version. The container with the application would crash with a "Segmentation fault" error.
This means the process tried to access memory it didnât have access to. Itâs not a logical error but something more seriousâa system-level or core issueâand itâs tough to diagnose.
The difficulty lies in the fact that you canât catch it with an exception and check the backtrace.
If your application is also running in a Docker container, the complexity increases.
This means the process tried to access memory it didnât have access to. Itâs not a logical error but something more seriousâa system-level or core issueâand itâs tough to diagnose.
The difficulty lies in the fact that you canât catch it with an exception and check the backtrace.
If your application is also running in a Docker container, the complexity increases.
This post is a note for the future in case a similar situation arises again. The assumption of this post is that youâre using a Linux-based container.
To solve the problem, use the gdb command.
To solve the problem, use the gdb command.
gdb stands for GNU Debugger. You can find installation instructions online.
First, add it to the system or install it temporarily in the Dockerfile and rebuild the container.
Second, copy the runtime file.
Second, copy the runtime file.
cp index.php test.php echo '<?php sleep(3600) > index.php'
This ensures the container starts correctly.
Third, access the container using the exec command.
gdb php test.php // or standalone script gdb php bin/console app:troubles
In gdb, use the following commands:
- bt (backtrace) â displays the stack,
- list â shows code fragments around the location where the error occurred.
Now, go to your favorite IDE and set a breakpoint just before that spot. Itâs highly likely that, upon rerunning, youâll get some trace.
For example, an exception after catching an exception.
For example, an exception after catching an exception.