repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
cc9a108
parent
9df8384
author
Eric Bower
date
2026-02-26 09:31:40 -0500 EST
fix(pssh): fix race
2 files changed,  +9, -2
M pkg/pssh/server.go
+4, -0
 1@@ -319,6 +319,8 @@ type SSHServer struct {
 2 	SessionsCreated  *prometheus.CounterVec
 3 	SessionsFinished *prometheus.CounterVec
 4 	SessionsDuration *prometheus.CounterVec
 5+
 6+	Mu sync.Mutex
 7 }
 8 
 9 func (s *SSHServer) ListenAndServe() error {
10@@ -379,7 +381,9 @@ func (s *SSHServer) ListenAndServe() error {
11 		return err
12 	}
13 
14+	s.Mu.Lock()
15 	s.Listener = listen
16+	s.Mu.Unlock()
17 	defer func() {
18 		_ = s.Listener.Close()
19 	}()
M pkg/pssh/server_test.go
+5, -2
 1@@ -520,8 +520,11 @@ func TestSSHServerCommandParsing(t *testing.T) {
 2 	// Wait for server to be ready and get the actual listening address
 3 	var actualAddr string
 4 	for i := 0; i < 50; i++ {
 5-		if server.Listener != nil {
 6-			actualAddr = server.Listener.Addr().String()
 7+		server.Mu.Lock()
 8+		listener := server.Listener
 9+		server.Mu.Unlock()
10+		if listener != nil {
11+			actualAddr = listener.Addr().String()
12 			break
13 		}
14 		time.Sleep(10 * time.Millisecond)