Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Error handling and logging improvements #9

Merged
merged 21 commits into from
Mar 18, 2019
Merged

Error handling and logging improvements #9

merged 21 commits into from
Mar 18, 2019

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Mar 14, 2019

Improve some error handling and logging in EthFirewall

  • Ensure can't set the http listen host and ports to the same values as the downstream host and port
  • Exit with error code if the http server fails to start
  • Add a request timeout so that we don't wait infinitely for a request to fail
  • Let Vertx handle any errors with the default error handler instead of just hanging (we will want add our own custom response http status codes at some point)
  • Improve logging for pass through proxy handler

@jframe jframe requested review from rain-on and CjHare March 14, 2019 23:49
@@ -78,7 +78,7 @@ public static void setupEthFirewall() throws IOException, CipherException {
httpServerOptions.setPort(serverSocket.getLocalPort());
httpServerOptions.setHost("localhost");

runner = new Runner(transactionSigner, httpClientOptions, httpServerOptions);
runner = new Runner(transactionSigner, httpClientOptions, httpServerOptions, 5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use the more descriptive TimeUnit JDK class i.e. TimeUnit.SECONDS.toMillis(5)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -49,6 +49,12 @@ public void run() {
return;
}

if (config.getHttpListenHost().equals(config.getHttpListenHost())
Copy link
Contributor

Choose a reason for hiding this comment

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

You're using string comparison here for integers, whitespace risk i.e. "1" != "1 "

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 config to now take InetAddress so that trailing spaces are no longer an issue. Also changed to use loopback as the default same what Pantheon is doing. Seems like a better default for security.

@Option(
names = {"--downstream-http-request-timeout"},
description =
"Timeout in ms to wait for downstream request to timeout (default: ${DEFAULT-VALUE})",
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the unit? minutes, seconds, milliseconds, nanoseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using milliseconds. Was using the ms abbreviation, but changed that to use milliseconds to make it clearer.

description =
"Timeout in ms to wait for downstream request to timeout (default: ${DEFAULT-VALUE})",
arity = "1")
private Integer downstreamHttpRequestTimeout = 5_000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the bounding appropriate for the time unit i.e.should this type be a 'Long'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. should be a long as that is what vertx accepts as the type.

assertThat(config.getDownstreamHttpPort()).isEqualTo(5000);
assertThat(config.getDownstreamHttpRequestTimeout()).isEqualTo(10000);
assertThat(config.getHttpListenHost()).isEqualTo("localhost");
assertThat(config.getHttpListenHost()).isEqualTo(InetAddress.getLoopbackAddress());
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth having different values for listen-host and downstream to prove we haven't copied the same cmdline arg in to 2 different params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea. done.

@@ -34,12 +34,12 @@

private final RequestMapper requestHandlerMapper;
private final HttpServerOptions serverOptions;
private final int httpRequestTimeout;
private final Long httpRequestTimeout;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use the unboxed versions of this when possible? (and others)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is better. I was following what we were doing for the other types. Thought maybe pico had problem but it's fine. So now we are using long

@@ -41,6 +42,10 @@ public void setServerOptions(final HttpServerOptions serverOptions) {
this.serverOptions = serverOptions;
}

public void setHttpRequestTimeout(final Long requestTimeout) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Long?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wanted to leave that there, otherwise I can't tell if it has been set. Though 0 for a timeout value doesn't seem particularly useful anyway.

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 to long. Validating that timeout > 0 as vertx doesn't allow 0 as a timeout value.

Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

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

Nice use of INetAddress

@@ -85,7 +85,7 @@ public static void setupEthFirewall() throws IOException, CipherException {
httpServerOptions.setPort(serverSocket.getLocalPort());
httpServerOptions.setHost("localhost");

runner = new Runner(transactionSigner, httpClientOptions, httpServerOptions);
runner = new Runner(transactionSigner, httpClientOptions, httpServerOptions, 5000L);
Copy link
Contributor

Choose a reason for hiding this comment

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

5000L -> TimeUnit.SECONDS.toMills(5)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. using Duration version


Integer getDownstreamHttpPort();

String getHttpListenHost();
long getDownstreamHttpRequestTimeout();
Copy link
Contributor

Choose a reason for hiding this comment

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

long doesn't inform the reader of the units.
How about using Duration instead?
https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jframe jframe merged commit 6c47feb into Consensys:master Mar 18, 2019
@jframe jframe deleted the error_handling_logging branch March 18, 2019 00:32
sambacha pushed a commit to freight-trust/ethsigner that referenced this pull request Oct 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants