domainaware / parsedmarc

A Python package and CLI for parsing aggregate and forensic DMARC reports
https://domainaware.github.io/parsedmarc/
Apache License 2.0
1.01k stars 219 forks source link

msgraph: ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) #479

Open PelaezLink opened 8 months ago

PelaezLink commented 8 months ago

Hello everyone. Since I switched to use msgraph API, every few days I get the following error that causes the Pod in which is running to restart. Most of the time is running ok, and reading the mailbox correctly from exchange. But this error comes up eventually with no reason:

`Traceback (most recent call last): File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 467, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 462, in _make_request httplib_response = conn.getresponse() File "/opt/pypy/lib/pypy3.9/http/client.py", line 1377, in getresponse response.begin() File "/opt/pypy/lib/pypy3.9/http/client.py", line 320, in begin version, status, reason = self._read_status() File "/opt/pypy/lib/pypy3.9/http/client.py", line 281, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/pypy/lib/pypy3.9/socket.py", line 704, in readinto return self._sock.recv_into(b) File "/opt/pypy/lib/pypy3.9/ssl.py", line 1297, in recv_into return self.read(nbytes, buffer) File "/opt/pypy/lib/pypy3.9/ssl.py", line 1133, in read return self._sslobj.read(len, buffer) File "/opt/pypy/lib/pypy3.9/_cffi_ssl/_stdssl/init.py", line 613, in read return self._read_buf(length, buffer_into) File "/opt/pypy/lib/pypy3.9/_cffi_ssl/_stdssl/init.py", line 725, in _read_buf raise pyssl_error(self, count) ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/pypy/lib/pypy3.9/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 799, in urlopen retries = retries.increment( File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/util/retry.py", line 550, in increment raise six.reraise(type(error), error, _stacktrace) File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/packages/six.py", line 769, in reraise raise value.with_traceback(tb) File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 715, in urlopen httplib_response = self._make_request( File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 467, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/opt/pypy/lib/pypy3.9/site-packages/urllib3/connectionpool.py", line 462, in _make_request httplib_response = conn.getresponse() File "/opt/pypy/lib/pypy3.9/http/client.py", line 1377, in getresponse response.begin() File "/opt/pypy/lib/pypy3.9/http/client.py", line 320, in begin version, status, reason = self._read_status() File "/opt/pypy/lib/pypy3.9/http/client.py", line 281, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/pypy/lib/pypy3.9/socket.py", line 704, in readinto return self._sock.recv_into(b) File "/opt/pypy/lib/pypy3.9/ssl.py", line 1297, in recv_into return self.read(nbytes, buffer) File "/opt/pypy/lib/pypy3.9/ssl.py", line 1133, in read return self._sslobj.read(len, buffer) File "/opt/pypy/lib/pypy3.9/_cffi_ssl/_stdssl/init.py", line 613, in read return self._read_buf(length, buffer_into) File "/opt/pypy/lib/pypy3.9/_cffi_ssl/_stdssl/init.py", line 725, in _read_buf raise pyssl_error(self, count) urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/pypy/bin/parsedmarc", line 8, in sys.exit(_main()) File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/cli.py", line 1160, in _main watch_inbox( File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/init.py", line 1536, in watch_inbox mailbox_connection.watch(check_callback=check_callback, File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/mail/graph.py", line 218, in watch check_callback(self) File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/init.py", line 1522, in check_callback res = get_dmarc_reports_from_mailbox(connection=connection, File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/init.py", line 1336, in get_dmarc_reports_from_mailbox messages = connection.fetch_messages(reports_folder, batch_size=batch_size) File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/mail/graph.py", line 149, in fetch_messages emails = self._get_all_messages(url, batch_size) File "/opt/pypy/lib/pypy3.9/site-packages/parsedmarc/mail/graph.py", line 161, in _get_all_messages result = self._client.get(url, params=params) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/_graph_client.py", line 46, in wrapper return func(*args, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/_graph_client.py", line 93, in get return self.graph_session.get(self._graph_url(url), kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/requests/sessions.py", line 602, in get return self.request("GET", url, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/middleware.py", line 44, in send return self._first_middleware.send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/authorization.py", line 23, in send response = super().send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/middleware.py", line 66, in send return self.next.send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/retry.py", line 118, in send response = super().send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/middleware.py", line 66, in send return self.next.send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/telemetry.py", line 22, in send response = super().send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/msgraph/core/middleware/middleware.py", line 65, in send return super().send(request, kwargs) File "/opt/pypy/lib/pypy3.9/site-packages/requests/adapters.py", line 501, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))`

Any recomendations for this? If the error is no avoidable, is there any way to avoid the liveness restart the pod? Thanks a lot

vasyugan commented 2 months ago

I'm seeing the same on a freshly installed instance on Debian Bookworm. It is unfortunate, that the traceback doesn't reveal whom it was trying to contact. I read that the reason might be a library incompatibility between the system and virtualenv, but isn't the purpose of virtualenv exactly to prevent such conflicts?

davidande commented 1 month ago

Hello, I got the same problem.

Elastic/Kibana 8.13 dockers Parsedmarc on WebTop docker MSGRAPH Dockers on a Synology NAS

Traceback (most recent call last):
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 462, in _make_request
    httplib_response = conn.getresponse()
                       ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/http/client.py", line 1428, in getresponse
    response.begin()
  File "/usr/lib/python3.12/http/client.py", line 331, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/http/client.py", line 300, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/.local/lib/python3.12/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 799, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/config/.local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 462, in _make_request
    httplib_response = conn.getresponse()
                       ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/http/client.py", line 1428, in getresponse
    response.begin()
  File "/usr/lib/python3.12/http/client.py", line 331, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/http/client.py", line 300, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/.local/bin/parsedmarc", line 8, in <module>
    sys.exit(_main())
             ^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/cli.py", line 1433, in _main
    watch_inbox(
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/__init__.py", line 1668, in watch_inbox
    mailbox_connection.watch(check_callback=check_callback,
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/mail/graph.py", line 219, in watch
    check_callback(self)
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/__init__.py", line 1650, in check_callback
    res = get_dmarc_reports_from_mailbox(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/__init__.py", line 1451, in get_dmarc_reports_from_mailbox
    messages = connection.fetch_messages(reports_folder, batch_size=batch_size)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/mail/graph.py", line 150, in fetch_messages
    emails = self._get_all_messages(url, batch_size)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/parsedmarc/mail/graph.py", line 162, in _get_all_messages
    result = self._client.get(url, params=params)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/_graph_client.py", line 46, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/_graph_client.py", line 93, in get
    return self.graph_session.get(self._graph_url(url), **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/middleware.py", line 44, in send
    return self._first_middleware.send(request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/authorization.py", line 23, in send
    response = super().send(request, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/middleware.py", line 66, in send
    return self.next.send(request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/retry.py", line 118, in send
    response = super().send(request, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/middleware.py", line 66, in send
    return self.next.send(request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/telemetry.py", line 22, in send
    response = super().send(request, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/msgraph/core/middleware/middleware.py", line 65, in send
    return super().send(request, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/.local/lib/python3.12/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
0it [4:06:12, ?it/s]
abc@webtop:~$