Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition in handling of cmd #33

Open
wrboyce opened this issue Feb 2, 2018 · 0 comments
Open

Race condition in handling of cmd #33

wrboyce opened this issue Feb 2, 2018 · 0 comments

Comments

@wrboyce
Copy link
Contributor

wrboyce commented Feb 2, 2018

==================
WARNING: DATA RACE
Write at 0x00c4201ba208 by goroutine 32:
  os/exec.(*Cmd).Wait()
      /usr/local/Cellar/go/1.9.2/libexec/src/os/exec/exec.go:450 +0x163
  github.com/resin-io/sshproxy.(*Server).handleRequests.func1.1()
      /Users/wrboyce/Dev/resin/.go/src/github.com/resin-io/sshproxy/sshproxy.go:249 +0x4c

Previous read at 0x00c4201ba208 by goroutine 30:
  github.com/resin-io/sshproxy.(*Server).handleRequests.func1()
      /Users/wrboyce/Dev/resin/.go/src/github.com/resin-io/sshproxy/sshproxy.go:269 +0x29b

Goroutine 32 (running) created at:
  github.com/resin-io/sshproxy.(*Server).handleRequests.func1()
      /Users/wrboyce/Dev/resin/.go/src/github.com/resin-io/sshproxy/sshproxy.go:248 +0x8a

Goroutine 30 (finished) created at:
  github.com/resin-io/sshproxy.(*Server).handleRequests()
      /Users/wrboyce/Dev/resin/.go/src/github.com/resin-io/sshproxy/sshproxy.go:246 +0xb0d
  github.com/resin-io/sshproxy.(*Server).handleChannels.func1()
      /Users/wrboyce/Dev/resin/.go/src/github.com/resin-io/sshproxy/sshproxy.go:176 +0x8a
==================

Reproducible using:

package sshproxy_test

import (
	"net"
	"time"
	"testing"

	"golang.org/x/crypto/ssh"
	"github.com/resin-io/sshproxy"
)

func TestRace(t *testing.T) {
	server, err := sshproxy.New("/tmp", "/bin/bash", false, nil, nil, nil)
	if err != nil {
		t.Errorf("error calling sshproxy.New :( %q", err)
	}
	port := "12345"
	go server.Listen(port)

	config := &ssh.ClientConfig{
		User: "user",
		Auth: []ssh.AuthMethod{
			ssh.Password("password"),
		},
		HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
			return nil
		},
	}
	for i := 0; i < 10; i++ {
		client, err := ssh.Dial("tcp", "localhost:12345", config)
		if err != nil {
			t.Errorf("Cannot connect to server :( %q", err)
		}
		session, err := client.NewSession()
		if err != nil {
			t.Errorf("Cannot create session :( %q", err)
		}
		time.Sleep(time.Second)
		_, err = session.SendRequest("exec", false, []byte{0, 0, 0, 4, 't', 'e', 's', 't'})
		if err != nil {
			t.Errorf("Cannot send exec request :( %q", err)
		}
		time.Sleep(time.Duration(i * 100) * time.Millisecond)
		client.Close()
	}
}
wrboyce added a commit that referenced this issue Apr 24, 2019
Connects-to: #33
Change-type: patch
Signed-off-by: Will Boyce <[email protected]>
wrboyce added a commit that referenced this issue Apr 24, 2019
Connects-to: #33
Change-type: patch
Signed-off-by: Will Boyce <[email protected]>
wrboyce added a commit that referenced this issue May 6, 2019
Connects-to: #33
Change-type: patch
Signed-off-by: Will Boyce <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant