Skip to content
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

Fix/vpn server client close logs #1325

Merged
merged 8 commits into from
Aug 8, 2022
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
2 changes: 1 addition & 1 deletion internal/vpn/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (c *Client) dialServer(appCl *app.Client, pk cipher.PubKey) (net.Conn, erro
}

if c.isClosed() {
// we need to signal outer code that connection object is inalid
// we need to signal outer code that connection object is invalid
// in this case
return nil, errors.New("client got closed")
}
Expand Down
22 changes: 14 additions & 8 deletions internal/vpn/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewServer(cfg ServerConfig, appCl *app.Client) (*Server, error) {
if err != nil {
return nil, fmt.Errorf("error getting default network interface: %w", err)
}
ifcs, hasMultiple := s.hasMutipleNetworkInterfaces(defaultNetworkIfcs)
ifcs, hasMultiple := s.hasMultipleNetworkInterfaces(defaultNetworkIfcs)
if hasMultiple {
if cfg.NetworkInterface == "" {
return nil, fmt.Errorf("multiple default network interfaces detected...set a default one for VPN server or remove one: %v", ifcs)
Expand Down Expand Up @@ -74,18 +74,18 @@ func NewServer(cfg ServerConfig, appCl *app.Client) (*Server, error) {
fmt.Println("Old IP forwarding values:")
fmt.Printf("IPv4: %s, IPv6: %s\n", ipv4ForwardingVal, ipv6ForwardingVal)

iptablesForwarPolicy, err := GetIPTablesForwardPolicy()
iptablesForwardPolicy, err := GetIPTablesForwardPolicy()
if err != nil {
return nil, fmt.Errorf("error getting iptables forward policy: %w", err)
}

fmt.Printf("Old iptables forward policy: %s\n", iptablesForwarPolicy)
fmt.Printf("Old iptables forward policy: %s\n", iptablesForwardPolicy)

s.defaultNetworkInterface = defaultNetworkIfc
s.defaultNetworkInterfaceIPs = defaultNetworkIfcIPs
s.ipv4ForwardingVal = ipv4ForwardingVal
s.ipv6ForwardingVal = ipv6ForwardingVal
s.iptablesForwardPolicy = iptablesForwarPolicy
s.iptablesForwardPolicy = iptablesForwardPolicy

return s, nil
}
Expand Down Expand Up @@ -245,14 +245,20 @@ func (s *Server) serveConn(conn net.Conn) {
defer close(connToTunDoneCh)

if _, err := io.Copy(tun, conn); err != nil {
print(fmt.Sprintf("Error resending traffic from VPN client to TUN %s: %v\n", tun.Name(), err))
// when the vpn-client is closed we get the error "EOF"
if err.Error() != io.EOF.Error() {
print(fmt.Sprintf("Error resending traffic from VPN client to TUN %s: %v\n", tun.Name(), err))
}
}
}()
go func() {
defer close(tunToConnCh)

if _, err := io.Copy(conn, tun); err != nil {
print(fmt.Sprintf("Error resending traffic from TUN %s to VPN client: %v\n", tun.Name(), err))
// when the vpn-client is closed we get the error "read tun: file already closed"
if err.Error() != "read tun: file already closed" {
print(fmt.Sprintf("Error resending traffic from TUN %s to VPN client: %v\n", tun.Name(), err))
}
}
}()

Expand Down Expand Up @@ -335,7 +341,7 @@ func (s *Server) shakeHands(conn net.Conn) (tunIP, tunGateway net.IP, unsecureVP

if err := WriteJSON(conn, &sHello); err != nil {
unsecureVPN()
return nil, nil, nil, fmt.Errorf("error finishing hadnshake: error sending server hello: %w", err)
return nil, nil, nil, fmt.Errorf("error finishing handshake: error sending server hello: %w", err)
}

return sTUNIP, sTUNGateway, unsecureVPN, nil
Expand Down Expand Up @@ -363,7 +369,7 @@ func (s *Server) sendServerErrHello(conn net.Conn, status HandshakeStatus) {
}
}

func (s *Server) hasMutipleNetworkInterfaces(defaultNetworkInterface string) ([]string, bool) {
func (s *Server) hasMultipleNetworkInterfaces(defaultNetworkInterface string) ([]string, bool) {
networkInterfaces := strings.Split(defaultNetworkInterface, "\n")
if len(networkInterfaces) > 1 {
return networkInterfaces, true
Expand Down
10 changes: 6 additions & 4 deletions pkg/app/appserver/rpc_ingress_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,12 @@ func (r *RPCIngressGateway) Read(req *ReadReq, resp *ReadResp) error {
copy(resp.B, buf[:resp.N])
}
if err != nil {
// we don't print warning if the conn is already closed
_, ok := r.cm.Get(req.ConnID)
if ok {
r.log.WithError(err).Warn("Received unexpected error when reading from server.")
if err.Error() != io.EOF.Error() {
// we don't print warning if the conn is already closed
_, ok := r.cm.Get(req.ConnID)
if ok {
r.log.WithError(err).Warn("Received unexpected error when reading from server.")
}
}
}

Expand Down