compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] `docker compose --env-file path up -d` hangs when `path` is a named pipe

Open felixfontein opened this issue 1 year ago • 2 comments

Description

See https://github.com/getsops/sops/issues/1470. When sops exec-file is used, it by default uses a named pipe (instead of writing the decrypted file to disk).

It seems that Compose tries to read the file three times, and two times of these happen in the call here: https://github.com/docker/compose/blob/3371227794f5f3645f4f19829c60a741635ed329/cmd/compose/compose.go#L605 I added fmt.Printf statements before and after that line, and I only got the second print after step 5 completed.

I'm not sure what is happening, since the code called there only seems to read the file once (https://github.com/compose-spec/compose-go/blob/main/dotenv/env.go#L51). Also I have no clue how to build Compose with modified source from other packages, so I cannot easily add more print statements there to try to get an idea :)

Steps To Reproduce

  1. Create a minimal Compose project with a single service.
  2. Run mkfifo envfile
  3. Run docker compose --env-file envfile up --detach
  4. In a separate window, run cat > envfile and press CTRL+D. This stops the first read.
  5. Run cat > envfile and press CTRL+D again. This stops the second read.
  6. Run cat > envfile and press CTRL+D again. This stops the third read, and Compose starts doing some work.

Compose Version

latest source version

Docker Environment

No response

Anything else?

No response

felixfontein avatar Mar 24 '24 16:03 felixfontein

env file is indeed read once early as compose command is executed (as some COMPOSE_XX variables can be declared and change the model loading logic), then again while parsing with compose-go library. I'm not sure about a 3rd time, anyway code is definitely not optimized to avoid multi-read of such a file.

ndeloof avatar Mar 26 '24 09:03 ndeloof

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 25 '24 00:08 github-actions[bot]