Skip to content

portfwdserver: fix half-close #3686

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
9 changes: 7 additions & 2 deletions pkg/portfwdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
package portfwdserver

import (
"context"
"errors"
"io"
"net"
"time"

"github.com/lima-vm/lima/pkg/bicopy"
"github.com/containers/gvisor-tap-vsock/pkg/tcpproxy"

"github.com/lima-vm/lima/pkg/guestagent/api"
)

Expand All @@ -35,7 +37,10 @@ func (s *TunnelServer) Start(stream api.GuestService_TunnelServer) error {
return err
}
rw := &GRPCServerRW{stream: stream, id: in.Id}
bicopy.Bicopy(rw, conn, nil)
proxy := tcpproxy.DialProxy{DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return conn, nil
}}
proxy.HandleConn(rw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike bicopy.Bicopy(), this ignores errors silently. I don't think this library should be used for anything in the current state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do then ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Port forwarding seems to be lima core functionality, and using a library makes it hard to get good logging, so It think the best way is to copy the missing bits from tcpproxy into our own implementation.

This may be related:
inetaf/tcpproxy#46

tcpproxy seems to be about

Package tcpproxy lets users build TCP proxies, optionally making routing decisions based on HTTP/1 Host headers and the SNI hostname in TLS connections.

Our usage seems to be hacky way to reuse part of the library.

It also says:

This package makes no API stability promises. If you depend on it, vendor it.

Other options:

  • Log errors in the wrappers we pass to tcpproxy
  • Fix tcpproxy to log errors properly

If nobody can own this code in lima we can use tcpproxy as a temporary quick fix.

return nil
}

Expand Down
Loading