Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/tunnel/pipebridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func awaitPair(

select {
case handlerErr = <-handlerChan:
select {
case tunnelErr = <-tunnelChan:
default:
}
cancel()
_ = stdoutWriter.Close()
_ = stdinWriter.Close()
tunnelErr = <-tunnelChan
case tunnelErr = <-tunnelChan:
cancel()
_ = stdoutWriter.Close()
Expand Down
32 changes: 32 additions & 0 deletions pkg/tunnel/pipebridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,35 @@ func TestRunPairPipesClosedAfterReturn(t *testing.T) {
t.Fatal("timed out waiting for write checks")
}
}

func TestRunPairJoinsTunnelWhenHandlerFinishesFirst(t *testing.T) {
t.Parallel()

pb, err := NewPipeBridge()
if err != nil {
t.Fatalf("NewPipeBridge() error = %v", err)
}
defer pb.Close()

tunnelExited := make(chan struct{})
tunnel := func(_ context.Context, stdin *os.File, _ *os.File) error {
buf := make([]byte, 1)
_, err := stdin.Read(buf) // blocks until stdin write end is closed
close(tunnelExited)
return err
}

handler := func(_ context.Context, _ *os.File, _ *os.File) error {
return nil
}

if err := pb.RunPair(context.Background(), tunnel, handler); err != nil {
t.Fatalf("RunPair() error = %v", err)
}

select {
case <-tunnelExited:
case <-time.After(2 * time.Second):
t.Fatal("tunnel goroutine was orphaned when handler finished first")
}
}
Loading