Skip to content

Comments

Add port conflict exception#4565

Merged
jframe merged 16 commits intohyperledger:mainfrom
gfukushima:add_port_conflict_exception
Nov 2, 2022
Merged

Add port conflict exception#4565
jframe merged 16 commits intohyperledger:mainfrom
gfukushima:add_port_conflict_exception

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

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
@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 <gabrielfukushima@gmail.com>
jframe
jframe previously requested changes Oct 28, 2022
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
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

}

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


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

}
}

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?

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
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 <gabrielfukushima@gmail.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
@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
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
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