]> git.ipfire.org Git - thirdparty/tornado.git/commit
Sort getaddrinfo result based on address family 2454/head
authorSilent-Nights <silentquote@gmail.com>
Mon, 23 Jul 2018 13:42:44 +0000 (15:42 +0200)
committerSilent-Nights <silentquote@gmail.com>
Mon, 23 Jul 2018 14:03:04 +0000 (16:03 +0200)
commit7ac75bd7ce61803102e03701fdc45d43da6bab68
treee3c89be3ce479d290223f4809dc6000b46fd01a6
parentd4eb8eb4eb5cc9a6677e9116ef84ded8efba8859
Sort getaddrinfo result based on address family

Putting getaddrinfo result in a set to eliminate duplicates causes race
 conditions because sets are unordered

For example consider 2 applications try to bind to many random ports at once
 in both IPV4 and IPV6.
App1: Bind to random IPV4 address and get port 50000
App2: Bind to random IPV6 address and get port 50000
App2: Try to bind to same port on IPV4 and fails as App1 already bound to it
The same goes for App1

To resolve this, we create the set explicitly outside the loop.
We order the returned list of getaddrinfo based on Address family.
We skip the iteration if the iteration tuple already in the set.
Otherwise we execute the loop.
tornado/netutil.py