diff options
author | Vladimir Gordiychuk <folyga@gmail.com> | 2017-07-26 00:35:26 +0300 |
---|---|---|
committer | Eric Anderson <ejona@google.com> | 2017-07-25 15:53:37 -0700 |
commit | 00fe090ac1e421c393277f8554b851c542319c98 (patch) | |
tree | f73d127fd0db4616eda9b728c4538818a3836105 /context | |
parent | 3731a5dfcca995b7959d1918288911d7187fff77 (diff) | |
download | grpc-grpc-java-00fe090ac1e421c393277f8554b851c542319c98.tar.gz |
context: Create TimeoutException only when deadline occurs
Use deadline on client calls lead to create TimeoutException even
if deadline not occurs yet. fillStacktrack very expensive operation
that allocate many unnecessary objects in heap. Now exception
creates only when deadline occurs.
Close #3272
Diffstat (limited to 'context')
-rw-r--r-- | context/src/main/java/io/grpc/Context.java | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/context/src/main/java/io/grpc/Context.java b/context/src/main/java/io/grpc/Context.java index 7501f46f6..b8c4fb2c5 100644 --- a/context/src/main/java/io/grpc/Context.java +++ b/context/src/main/java/io/grpc/Context.java @@ -700,7 +700,6 @@ public class Context { ScheduledExecutorService scheduler) { super(parent, deriveDeadline(parent, deadline), true); if (DEADLINE_KEY.get(this) == deadline) { - final TimeoutException cause = new TimeoutException("context timed out"); if (!deadline.isExpired()) { // The parent deadline was after the new deadline so we need to install a listener // on the new earlier deadline to trigger expiration for this context. @@ -708,7 +707,7 @@ public class Context { @Override public void run() { try { - cancel(cause); + cancel(new TimeoutException("context timed out")); } catch (Throwable t) { log.log(Level.SEVERE, "Cancel threw an exception, which should not happen", t); } @@ -716,7 +715,7 @@ public class Context { }, scheduler); } else { // Cancel immediately if the deadline is already expired. - cancel(cause); + cancel(new TimeoutException("context timed out")); } } uncancellableSurrogate = new Context(this, EMPTY_ENTRIES); |