17170: Fix closing pty/tty when nil.
authorTom Clegg <tom@curii.com>
Thu, 14 Jan 2021 04:22:51 +0000 (23:22 -0500)
committerTom Clegg <tom@curii.com>
Thu, 14 Jan 2021 04:27:58 +0000 (23:27 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/crunchrun/container_gateway.go

index 8b2fe4144059d03293129631f02a3738d0eb83fc..0d869ca7fc750f4969c5f423245dc1c860124b7d 100644 (file)
@@ -204,8 +204,6 @@ func (gw *Gateway) handleSSH(w http.ResponseWriter, req *http.Request) {
                }
                var pty0, tty0 *os.File
                go func() {
-                       defer pty0.Close()
-                       defer tty0.Close()
                        // Where to send errors/messages for the
                        // client to see
                        logw := io.Writer(ch.Stderr())
@@ -280,6 +278,8 @@ func (gw *Gateway) handleSSH(w http.ResponseWriter, req *http.Request) {
                                                fmt.Fprintf(ch.Stderr(), "pty failed: %s"+eol, err)
                                                break
                                        }
+                                       defer p.Close()
+                                       defer t.Close()
                                        pty0, tty0 = p, t
                                        ok = true
                                        var payload struct {