44 "context"
55 "fmt"
66 "net"
7+ "strings"
78 "sync"
89
910 guestagentclient "github.com/lima-vm/lima/pkg/guestagent/api/client"
@@ -42,6 +43,7 @@ func (p *ClosableListeners) Forward(ctx context.Context, client *guestagentclien
4243}
4344
4445func (p * ClosableListeners ) Remove (_ context.Context , protocol , hostAddress , guestAddress string ) {
46+ logrus .Debugf ("removing listener for hostAddress: %s, guestAddress: %s" , hostAddress , guestAddress )
4547 key := key (protocol , hostAddress , guestAddress )
4648 switch protocol {
4749 case "tcp" , "tcp6" :
@@ -65,7 +67,6 @@ func (p *ClosableListeners) Remove(_ context.Context, protocol, hostAddress, gue
6567
6668func (p * ClosableListeners ) forwardTCP (ctx context.Context , client * guestagentclient.GuestAgentClient , hostAddress , guestAddress string ) {
6769 key := key ("tcp" , hostAddress , guestAddress )
68- defer p .Remove (ctx , "tcp" , hostAddress , guestAddress )
6970
7071 p .listenersRW .Lock ()
7172 _ , ok := p .listeners [key ]
@@ -75,16 +76,21 @@ func (p *ClosableListeners) forwardTCP(ctx context.Context, client *guestagentcl
7576 }
7677 tcpLis , err := Listen (ctx , p .listenConfig , hostAddress )
7778 if err != nil {
78- logrus .Errorf ("failed to accept TCP connection: %v" , err )
79+ logrus .Errorf ("failed to listen to TCP connection: %v" , err )
7980 p .listenersRW .Unlock ()
8081 return
8182 }
83+ defer p .Remove (ctx , "tcp" , hostAddress , guestAddress )
8284 p .listeners [key ] = tcpLis
8385 p .listenersRW .Unlock ()
8486 for {
8587 conn , err := tcpLis .Accept ()
8688 if err != nil {
8789 logrus .Errorf ("failed to accept TCP connection: %v" , err )
90+ if strings .Contains (err .Error (), "pseudoloopback" ) {
91+ // don't stop forwarding because the forwarder has rejected a non-local address
92+ continue
93+ }
8894 return
8995 }
9096 go HandleTCPConnection (ctx , client , conn , guestAddress )
0 commit comments