Skip to content

Commit

Permalink
Fix caching interaction with UDP truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Apr 8, 2020
1 parent a1abc2b commit 6068f68
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions proxy/udp.go
Expand Up @@ -36,7 +36,11 @@ var udpOOBSize = func() int {
func (p Proxy) serveUDP(l net.PacketConn) error {
bpool := sync.Pool{
New: func() interface{} {
b := make([]byte, maxUDPSize)
// Use the same buffer size as for TCP and truncate later. UDP and
// TCP share the cache, and we want to avoid storing truncated
// response for UDP that would be reused when the client falls back
// to TCP.
b := make([]byte, maxTCPSize)
return &b
},
}
Expand Down Expand Up @@ -97,7 +101,8 @@ func (p Proxy) serveUDP(l net.PacketConn) error {
return
}
if rsize > maxUDPSize {
return
rsize = maxUDPSize
buf[2] |= 0x2 // mark response as truncated
}
_, _, werr := c.WriteMsgUDP(buf[:rsize], oobWithSrc(lip), raddr)
if err == nil {
Expand Down

0 comments on commit 6068f68

Please sign in to comment.