Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit bd1506f

Browse files
committed
Propagate TTL
1 parent c074ffc commit bd1506f

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

in_response.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function TChannelInResponse(id, options) {
5757
self.arg3 = emptyBuffer;
5858

5959
self.start = self.timers.now();
60+
self.timeout = 0;
6061

6162
self.finishEvent.on(self.onFinish);
6263
}

out_request.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ function TChannelOutRequest(id, options) {
6262
this.checksum = options.checksum || null;
6363
this.forwardTrace = options.forwardTrace || false;
6464

65-
// All self requests have id 0
6665
this.operations = null;
6766
this.timeHeapHandle = null;
6867
this.id = id;
@@ -80,10 +79,22 @@ function TChannelOutRequest(id, options) {
8079
this.drained = false;
8180
this.drainReason = '';
8281

82+
this.start = this.channel.timers.now();
83+
this.timeout = options.timeout || this.channel.maximumRelayTTL;
84+
85+
// Truncate timeout if parent deadline is sooner.
86+
if (this.parent) {
87+
var parentDeadline = this.parent.start + this.parent.timeout;
88+
var childDeadline = this.start + this.timeout;
89+
var deadline = Math.min(parentDeadline, childDeadline);
90+
this.timeout = Math.max(0, deadline - this.start);
91+
}
92+
8393
if (options.channel.tracer && !this.forwardTrace) {
8494
// new span with new ids
8595
this.setupTracing(options);
8696
}
97+
8798
}
8899

89100
inherits(TChannelOutRequest, EventEmitter);

v2/handler.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,15 @@ TChannelV2Handler.prototype.handleCallResponse = function handleCallResponse(res
391391

392392
var req = this.connection.ops.getOutReq(res.id);
393393

394+
if (!req) {
395+
// Drop call response frames for requests that expire.
396+
return;
397+
}
398+
399+
// Copy the timeout from request to response for propagation when the in
400+
// response is used as the parent context for an out request.
401+
res.timeout = req.timeout;
402+
394403
var channel = this.connection.channel;
395404

396405
channel.emitFastStat(

0 commit comments

Comments
 (0)