[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:
committed by
Jeffrey Wilcke
parent
0c17be92fb
commit
4ce7970340
@ -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
|
||||
|
Reference in New Issue
Block a user