Skip to content

Commit

Permalink
resume scheduler after experiencing backpressure from the underlying …
Browse files Browse the repository at this point in the history
…data source
  • Loading branch information
dignifiedquire committed Aug 29, 2016
1 parent 8bb0b80 commit 0e9c847
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/spdy-transport/protocol/base/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Scheduler.prototype.schedule = function schedule(data) {
};

Scheduler.prototype._read = function _read() {
if (this.isPaused())
this.resume();

if (this.count === 0)
return;

Expand Down
68 changes: 68 additions & 0 deletions test/spdy/transport-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,72 @@ describe('SPDY Transport', function() {
});
});
});

describe('backpressure', function() {
it('should resume after pressure is released', function(done) {

var pair = streamPair.create();

server = transport.connection.create(pair, {
protocol: 'spdy',
windowSize: 256,
isServer: true,
autoSpdy31: true
});

client = transport.connection.create(pair.other, {
protocol: 'spdy',
windowSize: 256,
isServer: false,
autoSpdy31: true
});

server.start(3.1);

client.start(3.1);

var buf = new Buffer(64 * 1024);
buf.fill('x');

client.request({
method: 'POST',
path: '/',
headers: {}
}, function(err, stream) {
assert(!err);

stream.write(buf);
stream.write(buf);

const write = pair.write.bind(pair)
pair.write = function(data, enc, cb) {
write(data, enc, cb);
// Simulate backpressure on the socket
return false;
}

setTimeout(function() {
// Resolve backpressure
pair.write = write;
}, 100);

stream.write(buf);
stream.end(buf);
});

server.on('stream', function(stream) {
stream.respond(200, {});

var received = 0;
stream.on('data', function(chunk) {
received += chunk.length;
});

stream.on('end', function() {
assert.equal(received, buf.length * 4);
done();
});
});
});
});
});

0 comments on commit 0e9c847

Please sign in to comment.