[release/1.3.4] 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

Conflicts:
	p2p/discover/udp_test.go
This commit is contained in:
Felix Lange
2016-01-22 16:08:23 +01:00
committed by Jeffrey Wilcke
parent 0c17be92fb
commit 4ce7970340
4 changed files with 123 additions and 7 deletions

View File

@ -455,8 +455,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.
@ -468,7 +471,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