Skip to content

Commit e05d3da

Browse files
authored
Do not reset timeout when client closing (#21)
* Do not reset timeout when client closing * Sender client reset timeouts between messages * fixup
1 parent a7442ab commit e05d3da

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/coreClient.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CoreClient {
3939
this.reconnectCount = 0;
4040
this.logstats;
4141
this.options = {};
42+
this.endState = false;
4243
}
4344

4445
/**
@@ -48,6 +49,7 @@ class CoreClient {
4849
* @param {integer} closeSleep - time in ms for scheduling closing, undefined = close now
4950
*/
5051
close(context, closeSleep) {
52+
this.endState = true;
5153
if(closeSleep) {
5254
this.timeoutClose(context, closeSleep);
5355
}else{
@@ -109,8 +111,10 @@ class CoreClient {
109111
* @param {object} context - event context
110112
*/
111113
resetTimeout(context) {
112-
this.cancelTimeout();
113-
this.timeoutClose(context, this.timeout);
114+
if(!this.endState) {
115+
this.cancelTimeout();
116+
this.timeoutClose(context, this.timeout);
117+
}
114118
}
115119

116120
/**

lib/receiverClient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ class Receiver extends CoreClient {
8383
Utils.printStatistic(context);
8484
}
8585

86-
//reset timer (simulaton of fetch)
87-
self.resetTimeout(context, self.options.recvListen);
88-
8986
//if received all expected messages and timeout is 0 close connection
9087
if (((!self.options.processReplyTo) || self.options.recvListen) && self.received === self.expected) {
9188
self.cancelTimeout();
9289
self.close(context, self.options.closeSleep);
9390
}
9491

92+
//reset timer
93+
self.resetTimeout(context, self.options.recvListen);
94+
9595
//add credit for drain
9696
if (!(self.options.duration > 0) &&
9797
(self.expected === 0) &&

lib/senderClient.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ class Sender extends CoreClient {
125125

126126
Utils.printMessage(message, this.options);
127127

128+
if (this.options.timeout > 0) {
129+
this.resetTimeout(context, false);
130+
}
131+
128132
if (this.options.logStats === 'endpoints') {
129133
Utils.printStatistic(context);
130134
}
@@ -149,6 +153,10 @@ class Sender extends CoreClient {
149153
context.sender.send(message);
150154
}
151155

156+
if (self.options.timeout > 0) {
157+
self.resetTimeout(context, false);
158+
}
159+
152160
Utils.printMessage(message, self.options);
153161

154162
if (self.options.logStats === 'endpoints') {

0 commit comments

Comments
 (0)