Skip to content

Commit bbc06f9

Browse files
author
michau-krakow
committed
Delay socket close so to (re)send final ACK if needed.
1 parent bb27e0a commit bbc06f9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/protocol/reader.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ Reader.prototype._notifyWindow = function (block){
157157

158158
if (this._lastReceived){
159159
this._noMoreData = true;
160-
return this._close ();
160+
this._readerTimer.reset ();
161+
// RFC 1350 section 6: On the other hand, delaying is encouraged. This means that the host sending the final
162+
// ACK will wait for a while before terminating in order to retransmit the final ACK if it has been lost
163+
return setTimeout(() => this._close(), 5000);
161164
}
162165

163166
this._pending = this._windowSize;
@@ -168,9 +171,11 @@ Reader.prototype._notifyWindow = function (block){
168171
};
169172

170173
Reader.prototype._onData = function (message){
171-
//DATA packet received after sending the last packet, the socket will be
172-
//closed in the next tick
173-
if (this._noMoreData) return;
174+
//DATA packet received after sending the last packet, the socket is delay-closed so just ACK the client
175+
if (this._noMoreData) {
176+
this._sendAck(message.block);
177+
return;
178+
}
174179

175180
if (message.block === 0 && this._rolloverFix === 0){
176181
//The server has rollovered to 0

0 commit comments

Comments
 (0)