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 port conflict exception #4565

Merged
merged 16 commits into from
Nov 2, 2022

Conversation

gfukushima
Copy link
Contributor

PR description

Added methods to check if port is available and call before starting websockets and rpc services.

Fixed Issue(s)

Fixes #4176

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Changelog

@gfukushima gfukushima marked this pull request as ready for review October 27, 2022 09:22
Copy link
Contributor

@fab-10 fab-10 left a comment

Choose a reason for hiding this comment

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

just a comment on the method name, then a general question, this covers listening ports of the RPC server, are the other listening ports already covered?

return false;
}

public static void checkPortsAvailable(final int tcpPort) {
Copy link
Contributor

Choose a reason for hiding this comment

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

then method name says Ports so suggests that more than one port as parameter like a var arg, otherwise use the singular

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the name of the method, thanks for raising that @fab-10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the approach to cover the ports we will require to initialise all the services defined in the config. So we can have a more general solution that loops through the ports and check if they are available.

Signed-off-by: Gabriel Fukushima <[email protected]>
Signed-off-by: Gabriel Fukushima <[email protected]>
Signed-off-by: Gabriel Fukushima <[email protected]>
Signed-off-by: Gabriel Fukushima <[email protected]>
if (!unavailablePorts.isEmpty()) {
throw new InvalidConfigurationException(
"Port(s) '"
+ unavailablePorts.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: toString on unavailablePorts isn't necessary

@@ -3126,6 +3127,25 @@ private void checkPortClash() {
});
}

private void checkIfRequiredPortsAreAvailable() {
List<Integer> unavailablePorts = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: final

@@ -219,6 +219,7 @@ public CompletableFuture<?> start() {

final CompletableFuture<?> resultFuture = new CompletableFuture<>();
try {

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason to add the extra empty line?

@jframe jframe dismissed their stale review October 31, 2022 05:10

changes have been made to check port conflicts for other services

@@ -98,4 +105,31 @@ public static void checkPort(final int port, final String portTypeName) {
"%s port requires a value between 1 and 65535. Got %d.", portTypeName, port));
}
}

public static boolean isPortAvailableForTcp(final int port) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be private?

return false;
}

public static boolean isPortAvailableForUdp(final int port) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could be private?

return false;
}

public static boolean isPortAvailable(final int port) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider renaming to make to clear this is checking both udp and tcp. maybe rename to isPortAvailableForTcpAndUdp

@jframe jframe merged commit 42260fd into hyperledger:main Nov 2, 2022
macfarla pushed a commit to jflo/besu that referenced this pull request Jan 10, 2023
Signed-off-by: Gabriel Fukushima <[email protected]>
Signed-off-by: Sally MacFarlane <[email protected]>
@gfukushima gfukushima deleted the add_port_conflict_exception branch January 13, 2023 07:08
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
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.

Better error when unable to start due to port conflict for json-rpc services
4 participants