Hi all,
I’m experiencing a memory leak issue (not sure at 100%) in my Erlang application running inside a Docker container and hoping someone might have insights or similar experiences to share.
Setup:
- Erlang release running in Docker
- Application performs image format conversion (any format → WebP)
- Using
open_port/2
to call external image conversion programs
Problem:
The Docker container’s memory usage continuously grows after each image conversion operation, suggesting a memory leak. The memory is not being reclaimed between conversions.
Code pattern (simplified):
convert_image(InputPath, OutputPath) ->
Cmd = io_lib:format("convert ~s ~s", [InputPath, OutputPath]),
Port = open_port({spawn, Cmd}, [exit_status, {line, 1024}]),
wait_for_port(Port).
wait_for_port(Port) ->
receive
{Port, {exit_status, 0}} ->
port_close(Port),
ok;
{Port, {exit_status, Status}} ->
port_close(Port),
{error, Status}
end.
Questions:
- Are there known issues with
open_port
memory management in containerized environments? - Should I be doing additional cleanup beyond
port_close/1
? - Could this be related to how Docker handles process cleanup vs. the Erlang VM?
- Has anyone experienced similar issues with external command execution in Docker?
Any insights, debugging suggestions, or similar experiences would be greatly appreciated.
Thanks.
System details:
- Erlang/OTP version: 28 [erts-16.0]
- Docker base image: Docker version 28.1.1, build 4eba377
- Host OS: Ubuntu 22.04 LTS