简体   繁体   中英

Tornado Python blocking on _socket.getaddrinfo

Python 3.4

Tornado 4.3

When using the AsyncHttpClient and catching any blocking calls > 1s I get this stacktrace once in a while.

_socket.getaddrinfo is blocking.

How could that be happening? Isn't the DNS cached? Slow domain resolution or network glitches?

IOLoop blocked for more than 1 seconds in
...
  response = yield client.fetch(request, raise_error=True)
File "/usr/local/lib/python3.4/dist-packages/tornado/httpclient.py", line 255, in fetch
  self.fetch_impl(request, handle_response)
File "/usr/local/lib/python3.4/dist-packages/tornado/simple_httpclient.py", line 133, in fetch_impl
  self._process_queue()
File "/usr/local/lib/python3.4/dist-packages/tornado/simple_httpclient.py", line 148, in _process_queue
  self._handle_request(request, release_callback, callback)
File "/usr/local/lib/python3.4/dist-packages/tornado/simple_httpclient.py", line 157, in _handle_request
  self.max_header_size, self.max_body_size)
File "/usr/local/lib/python3.4/dist-packages/tornado/simple_httpclient.py", line 236, in __init__
  callback=self._on_connect)
File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 230, in wrapper
  yielded = next(result)
File "/usr/local/lib/python3.4/dist-packages/tornado/tcpclient.py", line 164, in connect
  addrinfo = yield self.resolver.resolve(host, port, af)
File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 371, in wrapper
  future = getattr(self, executor).submit(fn, self, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 337, in submit
  future.set_result(fn(*args, **kwargs))
File "/usr/local/lib/python3.4/dist-packages/tornado/netutil.py", line 374, in resolve
  addrinfo = socket.getaddrinfo(host, port, family, socket.SOCK_STREAM)
File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
  for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

Depending on the configuration of your operating system, DNS lookup may or may not be cached. Mac OS X systems do cache for a minute or so, and Linux systems generally do not cache DNS in their default configuration.

By default, Tornado calls getaddrinfo directly and leaves it up to your system's implementation to cache the result or not. You can either configure your system with a cache, or accept that an occasional getaddrinfo call will be slow, or install a non-blocking resolver for Tornado like PyCARES or Twisted. See Tornado's documentation on configuring alternate resolvers for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM