Skip to content

HttpStatus.UNKNOWN should be retried #69

@dsaxton-1password

Description

@dsaxton-1password

Expected Behavior

Unknown HTTP status codes should also be retried. This is because they can sometimes be caused by things like TLS handshake timeouts which may be transient.

Current Behavior

Many records are failing to be sent to Amplitude in an AWS Lambda cold start situation because of errors such as this:

  • The handshake operation timed out
  • The write operation timed out

(Each with a -1 status code)

In theory these could be recoverable so we should try.

Possible Solution

One line code change:

--- a/src/amplitude/processor.py
+++ b/src/amplitude/processor.py
@@ -15,7 +15,7 @@ class ResponseProcessor:
         if res.status == HttpStatus.SUCCESS:
             self.callback(events, res.code, "Event sent successfully.")
             self.log(events, res.code, "Event sent successfully.")
-        elif res.status == HttpStatus.TIMEOUT or res.status == HttpStatus.FAILED:
+        elif res.status in (HttpStatus.TIMEOUT, HttpStatus.FAILED, HttpStatus.UNKNOWN):
             self.push_to_storage(events, 0, res)
         elif res.status == HttpStatus.PAYLOAD_TOO_LARGE:
             if len(events) == 1:

Steps to Reproduce

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions