Skip to content

Agent / PTY data race reading and resizing #3236

Closed
@spikecurtis

Description

@spikecurtis

Spotted during CI

Note that this trace is from a branch, and so line numbers might not be accurate to what is in main.

==================
WARNING: DATA RACE
Write at 0x00c00087af70 by goroutine 58:
  internal/poll.(*FD).destroy()
      /opt/hostedtoolcache/go/1.18.4/x64/src/internal/poll/fd_unix.go:86 +0xc9
  internal/poll.(*FD).readUnlock()
      /opt/hostedtoolcache/go/1.18.4/x64/src/internal/poll/fd_mutex.go:232 +0x44
  internal/poll.(*FD).Read.func1()
      /opt/hostedtoolcache/go/1.18.4/x64/src/internal/poll/fd_unix.go:147 +0x39
  runtime.deferreturn()
      /opt/hostedtoolcache/go/1.18.4/x64/src/runtime/panic.go:436 +0x32
  os.(*File).read()
      /opt/hostedtoolcache/go/1.18.4/x64/src/os/file_posix.go:31 +0xc7
  os.(*File).Read()
      /opt/hostedtoolcache/go/1.18.4/x64/src/os/file.go:119 +0x98
  github.com/coder/coder/pty.ReadWriter.Read()
      /home/runner/work/coder/coder/pty/pty.go:66 +0x6e
  github.com/coder/coder/pty.(*ReadWriter).Read()
      <autogenerated>:1 +0x7a
  io.copyBuffer()
      /opt/hostedtoolcache/go/1.18.4/x64/src/io/io.go:426 +0x28a
  io.Copy()
      /opt/hostedtoolcache/go/1.18.4/x64/src/io/io.go:385 +0xbb
  github.com/coder/coder/agent.(*agent).handleSSHSession.func4()
      /home/runner/work/coder/coder/agent/agent.go:468 +0x57

Previous read at 0x00c00087af70 by goroutine 93:
  os.(*File).Fd()
      /opt/hostedtoolcache/go/1.18.4/x64/src/os/file_unix.go:89 +0xa6
  github.com/creack/pty.Setsize()
      /home/runner/go/pkg/mod/github.com/creack/pty@v1.1.18/winsize_unix.go:23 +0x3d
  github.com/coder/coder/pty.(*otherPty).Resize()
      /home/runner/work/coder/coder/pty/pty_other.go:58 +0x104
  github.com/coder/coder/pty.(*otherPtyWithProcess).Resize()
      <autogenerated>:1 +0x67
  github.com/coder/coder/agent.(*agent).handleSSHSession.func2()
      /home/runner/work/coder/coder/agent/agent.go:458 +0x10a

Goroutine 58 (running) created at:
  github.com/coder/coder/agent.(*agent).handleSSHSession()
      /home/runner/work/coder/coder/agent/agent.go:467 +0xe9e
  github.com/coder/coder/agent.(*agent).init.func2()
      /home/runner/work/coder/coder/agent/agent.go:280 +0x97
  github.com/gliderlabs/ssh.(*session).handleRequests.func1()
      /home/runner/go/pkg/mod/github.com/gliderlabs/ssh@v0.3.4/session.go:261 +0x4b

Goroutine 93 (running) created at:
  github.com/coder/coder/agent.(*agent).handleSSHSession()
      /home/runner/work/coder/coder/agent/agent.go:456 +0xd06
  github.com/coder/coder/agent.(*agent).init.func2()
      /home/runner/work/coder/coder/agent/agent.go:280 +0x97
  github.com/gliderlabs/ssh.(*session).handleRequests.func1()
      /home/runner/go/pkg/mod/github.com/gliderlabs/ssh@v0.3.4/session.go:261 +0x4b

It's interesting that destroy is in the top stack --- which might mean the race occurs while the TTY is being closed and file descriptors being cleaned up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiArea: HTTP API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions