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

Add validation to Set(peers ...string) #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add validation to Set(peers ...string) #142

wants to merge 1 commit into from

Conversation

c9845
Copy link

@c9845 c9845 commented Oct 8, 2020

Check if each peers input value to Set(peers ...string) is a valid base URL as required and as noted in the func-level comments.

The prior version of Set() did not include any validation of the input value(s) even though the func-level comments noted "Each peer value should be a valid base URL, for example 'http://example.net:8000'". This could lead to confusion when a cluster of peers cannot communicate. For example, if a user called Set("localhost:8080") this may look correct but the host on which Set() was called will not be able to communicate with the peer provided via the address localhost:8080. This is compounded by the fact no error is returned, nor is anything logged, leading the user to believe the error is elsewhere besides with the inputted address.

To solve the above noted issue/confusion, Set() was modified to check if each input value is a valid URL and return an error when an input value is invalid. This is done by checking if the input URL has the required scheme (http or https since groupcache only uses http based communication at this point) and if a host was provided. Modifying the Set() func to return an error should not break anything since you can ignore return values from funcs.

The lines of code within the Set() func were reordered so that validation of input peer address could be done before setting of any pool data.

…h `peers` input value is a valid base URL with scheme as required and as noted in the func-level comments.

The prior version of `Set()` did not include any validation of the input value(s) even though the func-level comments noted "Each peer value should be a valid base URL, for example 'http://example.net:8000'".  This could lead to confusion when a cluster of peers cannot communicate.  For example, if a user called `Set("localhost:8080")` this may look correct but the host on which `Set()` was called will not be able to communicate with the peer provided via the address `localhost:8080`.  This is compounded by the fact no error is returned, nor is anything logged, leading the user to believe the error is elsewhere besides with the inputted address.

To solve the above noted issue/confusion, `Set()` was modified to check if each input value is a valid URL and return an error when an input value is invalid.  This is done by checking if the input URL has the required scheme (http or https since groupcache only uses http based communication at this point) and if a host was provided.  Modifying the `Set()` func to return an `error` should not break anything since you can ignore return values from funcs.

The lines of code within the `Set()` func were reordered so that validation of input peer address could be done before setting of any pool data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants