Skip to content

Commit

Permalink
Merge pull request #1150 from tonistiigi/ssh-release
Browse files Browse the repository at this point in the history
session: release forwarded ssh socket connection per connection
  • Loading branch information
AkihiroSuda authored Aug 28, 2019
2 parents 61e246a + bc3a1ee commit 96d13d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions session/sshforward/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"google.golang.org/grpc"
)

func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream) error {
func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream, closeStream func() error) error {
g, ctx := errgroup.WithContext(ctx)

g.Go(func() (retErr error) {
p := &BytesMessage{}
for {
if err := stream.RecvMsg(p); err != nil {
conn.Close()
if err == io.EOF {
return nil
}
conn.Close()
return errors.WithStack(err)
}
select {
Expand All @@ -42,6 +42,9 @@ func Copy(ctx context.Context, conn io.ReadWriteCloser, stream grpc.Stream) erro
n, err := conn.Read(buf)
switch {
case err == io.EOF:
if closeStream != nil {
closeStream()
}
return nil
case err != nil:
return errors.WithStack(err)
Expand Down
2 changes: 1 addition & 1 deletion session/sshforward/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *server) run(ctx context.Context, l net.Listener, id string) error {
return err
}

go Copy(ctx, conn, stream)
go Copy(ctx, conn, stream, stream.CloseSend)
}
})

Expand Down
2 changes: 1 addition & 1 deletion session/sshforward/sshprovider/agentprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (sp *socketProvider) ForwardAgent(stream sshforward.SSH_ForwardAgentServer)

eg.Go(func() error {
defer s1.Close()
return sshforward.Copy(ctx, s2, stream)
return sshforward.Copy(ctx, s2, stream, nil)
})

return eg.Wait()
Expand Down

0 comments on commit 96d13d6

Please sign in to comment.