Skip to content

Commit d475a21

Browse files
fhshanwen
authored andcommitted
ssh/agent: fix TestServerResponseTooLarge on Plan 9
First, modify the test to report a better error by waiting for the Marshal+Write goroutine to finish before returning from the test. If we return too early, a failure inside that goroutine can generate a panic. Second, we workaround plan9 not returning the actual number of bytes written on the connection in case of a hangup (due to closed connection). I've verified that syscall.Pwrite returns -1 on hangup in this particular case even when some data did get written. Fixes golang/go#35888 Change-Id: I7998cff926295f0d577b125c137021a9adc1be5a Reviewed-on: https://go-review.googlesource.com/c/crypto/+/209298 Reviewed-by: Han-Wen Nienhuys <[email protected]> Run-TryBot: Han-Wen Nienhuys <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent cda90e0 commit d475a21

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

ssh/agent/client_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"os/exec"
1515
"path/filepath"
16+
"runtime"
1617
"strconv"
1718
"strings"
1819
"sync"
@@ -317,6 +318,8 @@ func TestServerResponseTooLarge(t *testing.T) {
317318
if err != nil {
318319
t.Fatalf("netPipe: %v", err)
319320
}
321+
done := make(chan struct{})
322+
defer func() { <-done }()
320323

321324
defer a.Close()
322325
defer b.Close()
@@ -327,9 +330,21 @@ func TestServerResponseTooLarge(t *testing.T) {
327330

328331
agent := NewClient(a)
329332
go func() {
330-
n, _ := b.Write(ssh.Marshal(response))
333+
defer close(done)
334+
n, err := b.Write(ssh.Marshal(response))
331335
if n < 4 {
332-
t.Fatalf("At least 4 bytes (the response size) should have been successfully written: %d < 4", n)
336+
if runtime.GOOS == "plan9" {
337+
if e1, ok := err.(*net.OpError); ok {
338+
if e2, ok := e1.Err.(*os.PathError); ok {
339+
switch e2.Err.Error() {
340+
case "Hangup", "i/o on hungup channel":
341+
// syscall.Pwrite returns -1 in this case even when some data did get written.
342+
return
343+
}
344+
}
345+
}
346+
}
347+
t.Errorf("At least 4 bytes (the response size) should have been successfully written: %d < 4: %v", n, err)
333348
}
334349
}()
335350
_, err = agent.List()

0 commit comments

Comments
 (0)