Browse Source

Revert "socket.getaddrinfo on win32: do our own dns resolution outside the lock"

This reverts commit fc6cb70c80.
3.2.x
ThomasV 7 years ago
parent
commit
10f037c40c
  1. 20
      lib/network.py

20
lib/network.py

@ -31,12 +31,8 @@ from collections import defaultdict
import threading
import socket
import json
import sys
import dns
import dns.resolver
import socks
from . import util
from . import bitcoin
from .bitcoin import COIN
@ -448,22 +444,6 @@ class Network(util.DaemonThread):
socket.getaddrinfo = lambda *args: [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
else:
socket.socket = socket._socketobject
if sys.platform == 'win32':
# on Windows, socket.getaddrinfo takes a mutex, and might hold it for up to 10 seconds
# when dns-resolving. to speed it up drastically, we resolve dns ourselves, outside that lock
def fast_getaddrinfo(host, *args, **kwargs):
try:
if str(host) not in ('localhost', 'localhost.',):
answers = dns.resolver.query(host)
addr = str(answers[0])
else:
addr = host
except:
raise socket.gaierror(11001, 'getaddrinfo failed')
else:
return socket._getaddrinfo(addr, *args, **kwargs)
socket.getaddrinfo = fast_getaddrinfo
else:
socket.getaddrinfo = socket._getaddrinfo
@with_interface_lock

Loading…
Cancel
Save