moby / vpnkit

A toolkit for embedding VPN capabilities in your application
Apache License 2.0
1.09k stars 182 forks source link

Unlisten sockets after they disconnect #580

Closed fredericdalleau closed 2 years ago

fredericdalleau commented 2 years ago

After a successful connection forwarding to a server, if the server disappears, a tentative to connect the server again will be accepted by vpnkit even if vpnkit failed to reach the server. Ensure this does not occur by calling unlisten. Add test for valid and invalid connection cases

Signed-off-by: Frédéric Dalleau frederic.dalleau@docker.com

djs55 commented 2 years ago

Regarding the Windows failure: it might be a Windows firewall issue on the test running machine. Perhaps the test should be gated with something like

if Sys.os_type = "Win32" then begin
  ...
end else begin
  ...
end

Or maybe a timeout problem? This Go program:

package main

import (
  "fmt"
  "net"
  "time"
)

func main(){
  start := time.Now()
  _, err := net.Dial("tcp", "127.0.0.1:8080")
  if err != nil {
    fmt.Printf("rejected after %s\n", time.Since(start))
    return
  }
  fmt.Printf("connected after %s\n", time.Since(start))
}

takes >2s:


PS C:\Users\dave\go\src\connect-localhost> go build
PS C:\Users\dave\go\src\connect-localhost> .\connect-localhost.exe
rejected after 2.0195789s
yamt commented 2 years ago

i feel lucky today because this bug i hit today has already been fixed. thank you!

(i was investigating something not working well, which polls the availability of a service by tcp-connecting it.)