Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local dispatcher error handlers don't work #23

Open
jonashaag opened this issue Oct 13, 2017 · 0 comments
Open

Local dispatcher error handlers don't work #23

jonashaag opened this issue Oct 13, 2017 · 0 comments

Comments

@jonashaag
Copy link
Contributor

Using the local dispatcher (THORN_DISPATCHER = 'default'), not the Celery-based one, if the webhook raises an error (e.g. due to a timeout), the on_timeout and on_error handlers passed to send() aren't called. Instead the following internal error is raised:

  File "thorn/events.py", line 124, in send
    timeout=timeout, on_timeout=on_timeout,
  File "thorn/events.py", line 146, in _send
    allow_keepalive=self.allow_keepalive,
  File "thorn/dispatch/base.py", line 73, in send
    **kwargs
  File "vine/synchronization.py", line 57, in __init__
    [self.add_noincr(p) for p in promises or []]
  File "vine/synchronization.py", line 57, in <listcomp>
    [self.add_noincr(p) for p in promises or []]
  File "vine/synchronization.py", line 82, in add_noincr
    p.then(self)
AttributeError: 'NoneType' object has no attribute 'then'

I fixed (?) this with the following patch, although I am very unsure if it's correct. jonashaag@15453b2

Test case:

import django; django.setup()

import thorn
import thorn.django.models

thorn.django.models.Subscriber.objects.create(event='foo.*', url='http://8.8.8.8')

e = thorn.Event('foo.bar')
e.send({})

With my fix (?):

Traceback (most recent call last):
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/connection.py", line 83, in create_connection
    raise err
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/connection.py", line 73, in create_connection
    sock.connect(sa)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connection.py", line 146, in _new_conn
    (self.host, self.timeout))
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x10faddda0>, 'Connection to 8.8.8.8 timed out. (connect timeout=1)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "thorn/env3/lib/python3.6/site-packages/requests-2.18.4-py3.6.egg/requests/adapters.py", line 440, in send
    timeout=timeout
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "thorn/env3/lib/python3.6/site-packages/urllib3-1.22-py3.6.egg/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='8.8.8.8', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x10faddda0>, 'Connection to 8.8.8.8 timed out. (connect timeout=1)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    e.send({})
  File "thorn/thorn/events.py", line 124, in send
    timeout=timeout, on_timeout=on_timeout,
  File "thorn/thorn/events.py", line 146, in _send
    allow_keepalive=self.allow_keepalive,
  File "thorn/thorn/dispatch/base.py", line 73, in send
    **kwargs
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/synchronization.py", line 57, in __init__
    [self.add_noincr(p) for p in promises or []]
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/synchronization.py", line 57, in <listcomp>
    [self.add_noincr(p) for p in promises or []]
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/synchronization.py", line 82, in add_noincr
    p.then(self)
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/abstract.py", line 53, in then
    return self._p.then(on_success, on_error)
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/promises.py", line 173, in then
    callback.throw(self.reason)
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/synchronization.py", line 94, in throw
    self.p.throw(*args, **kwargs)
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/promises.py", line 217, in throw
    reraise(type(exc), exc, tb)
  File "thorn/env3/lib/python3.6/site-packages/vine-1.1.4-py3.6.egg/vine/five.py", line 178, in reraise
    raise value.with_traceback(tb)
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='8.8.8.8', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x10faddda0>, 'Connection to 8.8.8.8 timed out. (connect timeout=1)'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant