diff options
author | Felix Lange <fjl@twurst.com> | 2016-01-22 23:08:23 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-01-23 06:44:25 +0800 |
commit | 2871781f64958c144a15ccb4e64c005a10be7cdd (patch) | |
tree | 9a02049b55ffee03bb0f4fb97bb1c4b4b21f42d6 /p2p/discover/udp.go | |
parent | 78f196409552466ff878a030e4069495a923c73e (diff) | |
download | dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.tar dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.tar.gz dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.tar.bz2 dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.tar.lz dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.tar.xz dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.tar.zst dexon-2871781f64958c144a15ccb4e64c005a10be7cdd.zip |
p2p/discover: fix Windows-specific issue for larger-than-buffer packets
On Windows, UDPConn.ReadFrom returns an error for packets larger
than the receive buffer. The error is not marked temporary, causing
our loop to exit when the first oversized packet arrived. The fix
is to treat this particular error as temporary.
Fixes: #1579, #2087
Updates: #2082
Diffstat (limited to 'p2p/discover/udp.go')
-rw-r--r-- | p2p/discover/udp.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 72b2a45e5..cec9046a3 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -453,8 +453,11 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte, return packet, nil } -type tempError interface { - Temporary() bool +func isTemporaryError(err error) bool { + tempErr, ok := err.(interface { + Temporary() bool + }) + return ok && tempErr.Temporary() || isPacketTooBig(err) } // readLoop runs in its own goroutine. it handles incoming UDP packets. @@ -466,7 +469,7 @@ func (t *udp) readLoop() { buf := make([]byte, 1280) for { nbytes, from, err := t.conn.ReadFromUDP(buf) - if tempErr, ok := err.(tempError); ok && tempErr.Temporary() { + if isTemporaryError(err) { // Ignore temporary read errors. glog.V(logger.Debug).Infof("Temporary read error: %v", err) continue |