From bd1506fcea4602d4450c34852a0232481deb5cf1 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Tue, 19 Jan 2016 14:22:29 -0800 Subject: [PATCH] Propagate TTL --- in_response.js | 1 + out_request.js | 13 ++++++++++++- v2/handler.js | 9 +++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/in_response.js b/in_response.js index b70060c8a..e67cfc835 100644 --- a/in_response.js +++ b/in_response.js @@ -57,6 +57,7 @@ function TChannelInResponse(id, options) { self.arg3 = emptyBuffer; self.start = self.timers.now(); + self.timeout = 0; self.finishEvent.on(self.onFinish); } diff --git a/out_request.js b/out_request.js index de5e5098e..a88fe00c0 100644 --- a/out_request.js +++ b/out_request.js @@ -62,7 +62,6 @@ function TChannelOutRequest(id, options) { this.checksum = options.checksum || null; this.forwardTrace = options.forwardTrace || false; - // All self requests have id 0 this.operations = null; this.timeHeapHandle = null; this.id = id; @@ -80,10 +79,22 @@ function TChannelOutRequest(id, options) { this.drained = false; this.drainReason = ''; + this.start = this.channel.timers.now(); + this.timeout = options.timeout || this.channel.maximumRelayTTL; + + // Truncate timeout if parent deadline is sooner. + if (this.parent) { + var parentDeadline = this.parent.start + this.parent.timeout; + var childDeadline = this.start + this.timeout; + var deadline = Math.min(parentDeadline, childDeadline); + this.timeout = Math.max(0, deadline - this.start); + } + if (options.channel.tracer && !this.forwardTrace) { // new span with new ids this.setupTracing(options); } + } inherits(TChannelOutRequest, EventEmitter); diff --git a/v2/handler.js b/v2/handler.js index 0c8420b5f..ee9d97e26 100644 --- a/v2/handler.js +++ b/v2/handler.js @@ -391,6 +391,15 @@ TChannelV2Handler.prototype.handleCallResponse = function handleCallResponse(res var req = this.connection.ops.getOutReq(res.id); + if (!req) { + // Drop call response frames for requests that expire. + return; + } + + // Copy the timeout from request to response for propagation when the in + // response is used as the parent context for an out request. + res.timeout = req.timeout; + var channel = this.connection.channel; channel.emitFastStat(