ssh/tailssh: use background context for uploading recordings

Otherwise we see errors like
```
ssh-session(sess-20230322T005655-5562985593): recording: error sending recording to <addr>:80: Post "http://<addr>:80/record": context canceled
```

The ss.ctx is closed when the session closes, but we don't want to break the upload at that time. Instead we want to wait for the session to
close the writer when it finishes, which it is already doing.

Updates tailscale/corp#9967

Signed-off-by: Maisem Ali <maisem@tailscale.com>
(cherry picked from commit c350cd1f06)
pull/7789/head
Maisem Ali 2023-03-21 18:21:49 -07:00 committed by Denton Gentry
parent 40091d0261
commit 2474bd2754
No known key found for this signature in database
1 changed files with 6 additions and 1 deletions

View File

@ -1343,7 +1343,12 @@ func (ss *sshSession) startNewRecording() (_ *recording, err error) {
}
pr, pw := io.Pipe()
req, err := http.NewRequestWithContext(ss.ctx, "POST", fmt.Sprintf("http://%s:%d/record", recorder.Addr(), recorder.Port()), pr)
// We want to use a background context for uploading and not ss.ctx.
// ss.ctx is closed when the session closes, but we don't want to break the upload at that time.
// Instead we want to wait for the session to close the writer when it finishes.
ctx := context.Background()
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("http://%s:%d/record", recorder.Addr(), recorder.Port()), pr)
if err != nil {
pr.Close()
pw.Close()