Fix netProbe write check

Write at least 1 byte. This ensures that sockets are ready to use for writing.
Windows specific: during the system startup, sockets can be created but the underlying buffers may not be setup yet. If this is the case Write fails with WSAENOBUFS: "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
This fixes: https://github.com/jedisct1/dnscrypt-proxy/issues/841
This commit is contained in:
Mathias Berchtold 2019-05-30 23:16:21 +02:00 committed by Frank Denis
parent 7c8e20a533
commit cf261da79a
1 changed files with 4 additions and 1 deletions

View File

@ -623,7 +623,10 @@ func netProbe(address string, timeout int) error {
for tries := timeout; tries > 0; tries-- { for tries := timeout; tries > 0; tries-- {
pc, err := net.DialUDP("udp", nil, remoteUDPAddr) pc, err := net.DialUDP("udp", nil, remoteUDPAddr)
if err == nil { if err == nil {
_, err = pc.Write([]byte{}) // Write at least 1 byte. This ensures that sockets are ready to use for writing.
// Windows specific: during the system startup, sockets can be created but the underlying buffers may not be setup yet. If this is the case
// Write fails with WSAENOBUFS: "An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full"
_, err = pc.Write([]byte{ 0 })
} }
if err != nil { if err != nil {
if !retried { if !retried {