moby / vpnkit

A toolkit for embedding VPN capabilities in your application
Apache License 2.0
1.1k stars 187 forks source link

Udp: avoid possible duplicate flow #442

Closed djs55 closed 5 years ago

djs55 commented 5 years ago

If two UDP datagrams arrive from the same port, both threads will contend for the new_flow_lock mutex which is after the check to see if a hashtable record exists. Therefore both threads will create a hashtable entry for the same flow and bind 2 sockets.

We wish to keep the fast-path (already-established connections) fast, so rather than hold the mutex for the whole function we instead re-check the hashtable after acquiring the mutex.

Signed-off-by: David Scott dave.scott@docker.com