Ensure shell writers terminate with newline flush
What does this MR do?
- Updates
bash
shell to ensure that it terminates its script with a newline character to flush the contents. - Adds tests to ensure all shells do this and we don't have a regression.
Why was this MR needed?
In several cases, we copy scripts over stdin
to a remote host. By not terminating the script with a new-line, it's similar to typing out a command in a terminal (such as exit 0
) but then never hitting return.
This was discovered recently with our implementation of exec
for Docker: https://gitlab.com/gitlab-org/gitlab-runner/-/blob/v14.7.0/executors/docker/internal/exec/exec.go#L99. We rely on the underlying socket to support CloseWrite()
which does then perform a full flush of the script. However, not all socket implementations support CloseWrite()
(in this case, experimenting with a SSH tunnelled conn), so the remote shell had no idea that the script was in fact finished and was waiting for a terminating newline.
What's the best way to test this MR?
N/A
What are the relevant issue numbers?
Edited by Arran Walker