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

Fix/130 ignore socket errors #188

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

luismedel
Copy link

@luismedel luismedel commented Dec 4, 2024

This PR adds a way to ignore the dreaded socket.gaierror error when initializing the UDP client and a server is missing.

Details

The new constructor signature is:

StatsClient(host='localhost', port=8125, prefix=None, maxudpsize=512, ignore_socket_errors=False)

To complement this flag, I added the is_ready property and the reset() method to clients.

On the UDP client:

  • By default, the client will work as usual. When passing ignore_socket_errors=True, errors during the socket initialization will be ignored.
  • The is_ready property will reflect the state after the initialization.
  • In order to be able to recover from a failed initialization you can use the reset() method.

On streaming clients:

  • They will work as usual (won't ignore errors)
  • is_ready reflects the current status of the inner socket.
  • reset() calls reconnect() under the hood.

Extra

I added a quick Travis detection to skip the tests dynamically.

@@ -35,12 +36,18 @@ def eq_(a, b, msg=None):
assert a == b, msg


def _udp_client(prefix=None, addr=None, port=None, ipv6=False):
def _is_travis():
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to ignore Travis :-)

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

Successfully merging this pull request may close these issues.

socket.gaierror is raised if the host is not known Add a method to re-run DNS lookup
1 participant