mirror of https://github.com/grpc/grpc-java.git
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
This commit is contained in:
parent
3731a5dfcc
commit
00fe090ac1
|
|
@ -700,7 +700,6 @@ public class Context {
|
||||||
ScheduledExecutorService scheduler) {
|
ScheduledExecutorService scheduler) {
|
||||||
super(parent, deriveDeadline(parent, deadline), true);
|
super(parent, deriveDeadline(parent, deadline), true);
|
||||||
if (DEADLINE_KEY.get(this) == deadline) {
|
if (DEADLINE_KEY.get(this) == deadline) {
|
||||||
final TimeoutException cause = new TimeoutException("context timed out");
|
|
||||||
if (!deadline.isExpired()) {
|
if (!deadline.isExpired()) {
|
||||||
// The parent deadline was after the new deadline so we need to install a listener
|
// 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.
|
// on the new earlier deadline to trigger expiration for this context.
|
||||||
|
|
@ -708,7 +707,7 @@ public class Context {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
cancel(cause);
|
cancel(new TimeoutException("context timed out"));
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.log(Level.SEVERE, "Cancel threw an exception, which should not happen", t);
|
log.log(Level.SEVERE, "Cancel threw an exception, which should not happen", t);
|
||||||
}
|
}
|
||||||
|
|
@ -716,7 +715,7 @@ public class Context {
|
||||||
}, scheduler);
|
}, scheduler);
|
||||||
} else {
|
} else {
|
||||||
// Cancel immediately if the deadline is already expired.
|
// Cancel immediately if the deadline is already expired.
|
||||||
cancel(cause);
|
cancel(new TimeoutException("context timed out"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uncancellableSurrogate = new Context(this, EMPTY_ENTRIES);
|
uncancellableSurrogate = new Context(this, EMPTY_ENTRIES);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue