Skip to content

Commit 008ab12

Browse files
committed
tls: Prevent hang in readStart
This is not a great fix, and it's a bug that's very tricky to reproduce. Occasionally, while downloading a file, especially on Linux for some reason, the pause/resume timing will be just right such that the CryptoStream is in a 'reading' state, but actually has no data, so it ought to pull more in. Because there's no reads happening, it just sits there, and the process will exit This is, fundamentally, a factor of how the HTTP implementation sits atop CryptoStreams and TCP Socket objects, which is utterly horrible, and needs to be rewritten. However, in the meantime, npm downloads are prematurely exiting, causing hard-to-debug "cb() never called!" errors.
1 parent 31314b6 commit 008ab12

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/tls.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,18 @@ Object.defineProperty(CryptoStream.prototype, 'readyState', {
645645
function CleartextStream(pair, options) {
646646
CryptoStream.call(this, pair, options);
647647

648+
// This is a fake kludge to support how the http impl sits
649+
// on top of net Sockets
648650
var self = this;
649651
this._handle = {
650652
readStop: function() {
651653
self._reading = false;
652654
},
653655
readStart: function() {
654-
if (self._reading) return;
656+
if (self._reading && self._readableState.length > 0) return;
655657
self._reading = true;
656658
self.read(0);
659+
if (self._opposite.readable) self._opposite.read(0);
657660
}
658661
};
659662
}

0 commit comments

Comments
 (0)