mixpanel / mixpanel-python

Official Mixpanel Python library.
https://mixpanel.com/help/reference/python
Other
102 stars 85 forks source link

ConnectionResetError(104, 'Connection reset by peer') #118

Closed ahsas5 closed 1 year ago

ahsas5 commented 1 year ago

while trigger mixpanel event from our dev env via the celery as job queue & rabbitMq as broker, I am facing this issue.

Any help on this?

detailed traceback :

[2023-02-07 12:41:32,483: ERROR/MainProcess] FAILED TO trigger event for user_type:Farmer for  event_name:Application State in Backend with ERROR: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) and tb:Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1345, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/usr/local/lib/python3.9/ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1345, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
  File "/usr/local/lib/python3.9/ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/local/lib/python3.9/ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
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 "/usr/local/lib/python3.9/site-packages/mixpanel/__init__.py", line 615, in _write_request
    response = self._session.post(
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 547, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/app/farmer_financing/signals.py", line 89, in fire_specific_user_property_event
    Event().fire_event(
  File "/app/common/external/moengage_mixpanel_events.py", line 92, in fire_event
    mixpanel.people_set(
  File "/usr/local/lib/python3.9/site-packages/mixpanel/__init__.py", line 238, in people_set
    return self.people_update({
  File "/usr/local/lib/python3.9/site-packages/mixpanel/__init__.py", line 392, in people_update
    self._consumer.send('people', json_dumps(record, cls=self._serializer))
  File "/usr/local/lib/python3.9/site-packages/mixpanel/__init__.py", line 594, in send
    self._write_request(self._endpoints[endpoint], json_message, api_key, api_secret)
  File "/usr/local/lib/python3.9/site-packages/mixpanel/__init__.py", line 623, in _write_request
    six.raise_from(MixpanelException(e), e)
  File "<string>", line 3, in raise_from
mixpanel.MixpanelException: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
wnwjq462 commented 1 year ago

I am facing this issue too. from 14 Jan 2023.

shravan-schmooze commented 1 year ago

I'm also facing this issue very often.

ahsas5 commented 1 year ago

@wnwjq462 @shravan-schmooze try by not using Singleton class as the mixpanel class.

DimaDDM commented 1 year ago

Same issue

TomRaz commented 1 year ago

Same issue

thentgesMindee commented 1 year ago

We also had the same issue, and managed to fix it by following this answer:

@wnwjq462 @shravan-schmooze try by not using Singleton class as the mixpanel class.

Using a new instance of Mixpanel for every API call instead of the Singleton seems to be working. We used to have more than 5% of our events not being sent correctly, since we made the change (about a week ago) we didn’t see any new error.