Skip to content

updateref: Return context cancellation error

John Cai requested to merge jc/check-context-in-updater into master

12016efa (command: Improve error handling for stdout, 2023-08-31) started to close stdin when the context is canceled. However, there is a race condition between when we close stdin and when the Go standard library kills the process due to context cancellation.

This poses a problem in Updater because context cancellation will lead to indeteriminate results.

When a context is canceled, the Go standard library kills the process asynchronously. If this happens before we call u.cmd.Wait() in closeWithError(), we get a "context canceled" error which is expected. However, if the process exits successfully before the Go standard library notices the context cancellation and kills the process, u.cmd.Wait() does not return an error and we end up returning the error we get when trying to write to stdin, which would be a "file already closed" error.

Fix this in command by always returning context.Canceled in closeWithError().

fixes: #5650 (closed)

Edited by John Cai

Merge request reports