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

properly handle integer environment values, fixes issue with specifying ports via environment vars #2947

Merged
merged 2 commits into from
May 18, 2020

Conversation

thebubbleindex
Copy link
Contributor

make sure tcp and udp port for dht are int type

Reason for fix (Ubuntu 20.04 and desktop app):

  1. Without fix users specify env vars, LBRY_TCP_PORT=34562 and LBRY_UDP_PORT=34562, but then when you run the daemon it complains about string comparisons.
  2. With this fix people can download the desktop application, set the above environment variables and have their seeding working with VPN! PIA VPN gives you a randomly assigned port forward port, with this fix a user can now use a VPN (with ENV vars).

@eukreign
Copy link
Member

eukreign commented May 7, 2020

Thanks for the PR!

The proper place to fix this is in the conf.py module, it is already doing the conversion to int there, so if the conversion is not working this is a bug and we would need a test showing it failing and then the accompanying fix:

Where conversion is already being done:

return int(value)

Tests that need to be updated to reproduce the problem you are experiencing:

def test_environment(self):
c = TestConfig()
self.assertEqual(c.test_str, 'the default')
c.set_environment({'LBRY_TEST_STR': 'from environ'})
self.assertEqual(c.test_str, 'from environ')

@thebubbleindex
Copy link
Contributor Author

Might need some help, I cannot find where the environment variables are being converted into a type.

class EnvironmentAccess:

@eukreign
Copy link
Member

eukreign commented May 8, 2020

I think you've found the problem, if you look at the ArgumentAccess and ConfigFileAccess they all have load() methods which are called in __init__ to deserialize() the arguments but the EnvironmentAccess does not have one.

@thebubbleindex
Copy link
Contributor Author

thebubbleindex commented May 8, 2020

Thanks! I updated the conf.py to a working version, adding some type parsing and loading to the EnivronmentAccess

https://github.com/thebubbleindex/lbry-sdk/blob/eee50645c2c3b0ac2203716c6c6fead3134f5151/lbry/conf.py#L277

@eukreign
Copy link
Member

eukreign commented May 8, 2020

It should be very close to how ArgumentAccess works and loop over all of the pre-defined settings and look for them inside the environment: for setting in self.configuration.get_settings().

Also, this needs tests, they would go here: https://github.com/lbryio/lbry-sdk/blob/master/tests/unit/test_conf.py#L91 (look at all of the other tests in that file to get inspiration).

You are making good progress, don't hesitate to ask about how something work if you are confused, this conf code in LBRY heavily uses Python descriptors which are explained here:

https://docs.python.org/3/howto/descriptor.html
https://docs.python.org/3.7/reference/datamodel.html#implementing-descriptors
https://docs.python.org/3.7/reference/datamodel.html#invoking-descriptors

@thebubbleindex
Copy link
Contributor Author

Cool, think I have it now. I'll try to add the tests (I'm new to Python, but the examples you mentioned should be enough). Cheers!

@eukreign
Copy link
Member

eukreign commented May 9, 2020

Looking good! Instead of adding two new config options to the test config could you just re-use test_int that's already there (it's type Integer).

@tzarebczan
Copy link
Contributor

tzarebczan commented May 11, 2020

@thebubbleindex thanks for the PR, congrats on your first one!

Can we show you some appreciation for the contribution?

Also, please consider signing up for our dev list at the bottom of lbry.tech!

thebubbleindex and others added 2 commits May 18, 2020 08:53
make sure tcp and udp port for dht are int type
@eukreign eukreign changed the title fix issue with specifying ports via env vars properly handle integer environment values, fixes issue with specifying ports via environment vars May 18, 2020
@eukreign eukreign merged commit 46ef6c8 into lbryio:master May 18, 2020
@eukreign eukreign added area: config type: improvement Existing (or partially existing) functionality needs to be changed labels May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: config type: improvement Existing (or partially existing) functionality needs to be changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants