raven-aiohttp icon indicating copy to clipboard operation
raven-aiohttp copied to clipboard

QueuedAioHttpTransport throwing ServerDisconnectedError/ClientOSError exceptions.

Open bt-wil opened this issue 7 years ago • 2 comments

Environment (python v3.6):

aiohttp==2.2.5
raven==6.1.0
raven-aiohttp==0.6.0
sentry==8.22.0

I tried using the QueuedAioHttpTransport for the transport and noticed that it generates errors if there are too many alerts firing.

#!/usr/bin/env python3
import asyncio
from functools import partial
import logging

import raven
from raven.handlers.logging import SentryHandler
from raven_aiohttp import QueuedAioHttpTransport


logging.basicConfig(
    format='[%(asctime)s] %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
    level=logging.INFO
)
LOG = logging.getLogger(__name__)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()

    dsn = 'http://<key>:<secret>@localhost:9000/1'
    transport = partial(QueuedAioHttpTransport, workers=1, loop=loop, keepalive=True)

    client = raven.Client(dsn, transport=transport)
    handler = SentryHandler(client)
    handler.setLevel(logging.ERROR)
    logging.getLogger().addHandler(handler)

    for _ in range(2):
        LOG.error('test')

    loop.run_until_complete(client.remote.get_transport().close())
    loop.close()

Running the script produces:

[2017-12-06 12:10:30] ERROR - test
[2017-12-06 12:10:30] ERROR - test
[2017-12-06 12:10:30] ERROR - Sentry responded with an error: None (url: http://localhost:9000/api/1/store/)
Traceback (most recent call last):
  File "<lib-path>raven-aiohttp/raven_aiohttp.py", line 96, in _do_send
    timeout=self.timeout
  File "<env-path>/lib/python3.6/site-packages/aiohttp/helpers.py", line 97, in __iter__
    ret = yield from self._coro
  File "<env-path>/lib/python3.6/site-packages/aiohttp/client.py", line 241, in _request
    yield from resp.start(conn, read_until_eof)
  File "<env-path>/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 559, in start
    (message, payload) = yield from self._protocol.read()
  File "<env-path>/lib/python3.6/site-packages/aiohttp/streams.py", line 509, in read
    yield from self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: None
b'Sentry responded with an error: None (url: http://localhost:9000/api/1/store/)'
[2017-12-06 12:10:30] ERROR - ['test']
b"['test']"

Sometimes, aiohttp.client_exceptions.ClientOSError would be thrown instead of aiohttp.client_exceptions.ServerDisconnectedError. Using AioHttpTransport as the transport did not cause any issue.

bt-wil avatar Dec 06 '17 22:12 bt-wil

Does messages in this case successfully send to the sentry on not?

hellysmile avatar Feb 13 '18 14:02 hellysmile

No, the messages gets lost.

bt-wil avatar Mar 15 '18 01:03 bt-wil