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

Adding connectivity check and warning warning #43

Merged
merged 4 commits into from
May 7, 2024

Conversation

valefar-on-discord
Copy link
Collaborator

Adding a check when running the CLI to see if the user has an active internet connection and warn them if so.
Also adding a flag --ignore-connectivity which will not run the check.

I tried to add a test with the CLIRunner and ran into a bit of an issue where the tests have no problem waiting for inputs through click.prompt, but when using click.pause which allows for any keypress, it appears the tests ignore this.
I didn't want to go over the top on using prompt and having the user acknowledge in a specific manner. I feel a keypress is fine.

Fixes #17

Checks if there is an internet connection and warns the user if so.
'''
try:
urlopen('https://www.google.com/', timeout=2)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of this test here. It potentially tests too much (DNS, TCP, HTTPS, TLS and maybe a few other). For any quick replies, it would give a strong confidence that an Internet connection is present, but there is a non-significant chance of timeout and false negative.

I think I would prefer something like this DNS resolution:

import socket # up in the import section

socket.setdefaulttimeout(2)
socket.getaddrinfo('icann.org', 80)

icann.org being a domain name that is less likely to be blocked in Russia, China, Iran, Turkmenistan, Libya, and Sudan among others.

A DNS test is not perfect, but it would fail faster on a non-connected device. It would also reduce the false negatives.

Copy link
Member

Choose a reason for hiding this comment

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

See https://docs.python.org/3/library/socket.html for the socket module documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I missed the socket callout in the issue notes.
Updated.

@remyroy
Copy link
Member

remyroy commented May 7, 2024

I think --non_interactive should imply --ignore_connectivity meaning that if you use the --non_interactive flag, you don't need to also specify the --ignore_connectivity, it will simply be enabled, ie calling the app in a non interactive way shouldn't check or stop for Internet.

socket.setdefaulttimeout(2)
socket.getaddrinfo('icann.org', 80)
click.pause(load_text(['connectivity_warning']))
except: # noqa: E722
Copy link
Member

Choose a reason for hiding this comment

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

This should only catch OSError since all socket exceptions are subclasses of OSError and that should enable us to catch anything raised by socket calls here. It will also enable us to remove the noqa: E722.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ack

@valefar-on-discord
Copy link
Collaborator Author

Updated to ignore connectivity check if non_interactive is provided.
Created test_deposit.py to test out this functionality as well along with some unit tests.
Lastly there is a python version check that previously verified 3.7+. I have updated this to 3.9+ as:

  • 3.7 is currently EoL
  • 3.8 will be EoL starting in Oct 2024
  • Our CI verified 3.9+

Copy link
Member

@remyroy remyroy left a comment

Choose a reason for hiding this comment

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

Seems good.

@remyroy remyroy merged commit ecd202a into eth-educators:main May 7, 2024
15 checks passed
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.

Internet connectivity warning on load
2 participants