Skip to content

Commit b9f95cf

Browse files
Stream bug fix, version 1.0.30
1 parent 26581ed commit b9f95cf

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uquik",
3-
"version": "1.0.29",
3+
"version": "1.0.30",
44
"description": "uQuik HTTP(S) framework",
55
"main": "index.js",
66
"scripts": {

src/Response.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class Response extends Writable {
396396
// Attempt to stream the chunk using appropriate uWS.Response chunk serving method
397397
// This will depend on whether a total_size is specified or not
398398
let sent, finished
399-
// const lastOffset = this.write_offset
399+
const lastOffset = this.write_offset
400400
if (totalSize) {
401401
// Attempt to stream the current chunk using uWS.tryEnd with a total size
402402
const [ok, done] = this.raw_response.tryEnd(chunk, totalSize)
@@ -418,12 +418,20 @@ class Response extends Writable {
418418
stream.pause()
419419

420420
// Bind a drain handler which will resume the once the backpressure is cleared
421-
this.drain(() => {
422-
// Resume the stream if it is paused
423-
if (stream.isPaused()) stream.resume()
424-
425-
// Return the write boolean to uWS based on whether the stream is active or not
426-
return !stream.isPaused()
421+
this.drain((offset) => {
422+
if (lastOffset !== -1) {
423+
const [ok, done] = this.raw_response.tryEnd(chunk.slice(offset - lastOffset), totalSize)
424+
if (done) {
425+
if (!stream.destroyed) stream.destroy()
426+
} else if (ok) {
427+
// Resume the stream if it is paused
428+
if (stream.isPaused()) stream.resume()
429+
}
430+
/* We always have to return true/false in onWritable.
431+
* If you did not send anything, return true for success. */
432+
return ok
433+
}
434+
return true
427435
})
428436
}
429437
}

0 commit comments

Comments
 (0)