Wait for copy to complete before propagating exit-status. #1647
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Occasionally Teleport session recordings don't contain the end of a session. This happens because of a race condition between when everything has been copied from the PTY and when
exit-status
has been received by the server. To fix this problem, the PTY is not closed until everything has been copied from the PTY.Implementation
io.Copy
from the PTY to the writer (which is the session recorder and a direct connection to the remote client) and another goroutine that waits until eitherexit-status
has been received (for the forwarding node) orexec.Cmd
is complete (regular Teleport).doneCh
to notify the goroutine that is waiting for the execution of the shell to complete to also wait for theio.Copy
to finish before broadcasting theexit-status
to the client. This has to be done because broadcasting of theexit-status
causes the PTY to be closed.Related Issues
Fixes #1646