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

config: Add warning if EndpointAddress and NetAddress ports are equal #6006

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

hsoerensen
Copy link
Contributor

Summary

Log warning if EndpointAddress and NetAddress has identical ports.

This can happen in a scenario where NetAddress is set to listen to port 0.0.0.0:8080, and where no EndpointAddress is defined. In that case NetAddress is set to listen to 127.0.0.1:0 (port 0 being random OS assigned port in a specific range), however the makeListener func in daemon/algod/server.go has logic that sets the port to be port 8080 in case port 0 is provided (https://github.com/algorand/go-algorand/blob/master/daemon/algod/server.go#L256).

This will result in the following:

  • REST API will be accepting incoming connections on 127.0.0.1:8080
  • Gossip protocol will be accepting incoming connections on 0.0.0.0:8080, which will result in it binding to port 8080 for all IP's but 127.0.0.0.1

If you are like me this can cause a lot of confusion as paths and service responses now will default to standard 404 messages and payloads.

The proposed change will add a log warning if the two ports matches up.

Reasoning for a warning is that changing existing logic where port 0 implicitly means port 8080 may be a breaking change for anyone depending on the existing behavior, and where in some cases it could be assumed that people find this desirable (even if not following convention of using port 0).

Note that this PR does not change behavior regarding which address to bind to, meaning that a configuration such as the one below will continue to be a fatal error.

  "EndpointAddress": "127.0.0.1:8080",
  "NetAddress": "127.0.0.1:8080",

Test Plan

  • Remove any presence of EndpointAddress/NetAddress from config.json. No warning should be logged, as not in listening mode.
  • Add "NetAddress": "0.0.0.0:8080", to config.json. Warning should be logged.
  • Add "EndpointAddress": "0.0.0.0:8080", "NetAddress": "0.0.0.0:8081",. No warning should be logged.
  • Add "EndpointAddress": "127.0.0.1:8080", "NetAddress": "[::1]:8080",. Warning should be logged.

@algorandskiy algorandskiy changed the title Add warning if EndpointAddress and NetAddress ports are equal. config: Add warning if EndpointAddress and NetAddress ports are equal. Jun 11, 2024
@algorandskiy
Copy link
Contributor

Please also rebase on top of master.

@hsoerensen hsoerensen force-pushed the add-warn-on-matching-ports branch from 83fa1b9 to 790fae0 Compare June 11, 2024 21:32
@hsoerensen hsoerensen force-pushed the add-warn-on-matching-ports branch from 9d2f5c8 to 020e801 Compare June 11, 2024 22:06
@hsoerensen
Copy link
Contributor Author

@algorandskiy Refactored the code based on your feedback.

Tests are failing, but I don't have insights into why as CircleCI seems to be gated and with no public access. Would you be able to check?

@cce cce closed this Jun 12, 2024
@cce cce reopened this Jun 12, 2024
daemon/algod/server.go Outdated Show resolved Hide resolved
daemon/algod/server.go Outdated Show resolved Hide resolved
@algorandskiy algorandskiy changed the title config: Add warning if EndpointAddress and NetAddress ports are equal. config: Add warning if EndpointAddress and NetAddress ports are equal Jun 12, 2024
Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Project coverage is 55.88%. Comparing base (a5aac42) to head (0880b0b).
Report is 1 commits behind head on master.

Files Patch % Lines
daemon/algod/server.go 0.00% 16 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6006   +/-   ##
=======================================
  Coverage   55.88%   55.88%           
=======================================
  Files         482      482           
  Lines       68447    68463   +16     
=======================================
+ Hits        38252    38261    +9     
- Misses      27594    27607   +13     
+ Partials     2601     2595    -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@algorandskiy algorandskiy requested review from cce and gmalouf June 12, 2024 16:46
@gmalouf gmalouf merged commit 4e116cb into algorand:master Jun 12, 2024
19 checks passed
@hsoerensen hsoerensen deleted the add-warn-on-matching-ports branch June 13, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants