Skip to content

Commit

Permalink
Fix writableHighWaterMark==0 breaking on Node 20
Browse files Browse the repository at this point in the history
Fixes #128
  • Loading branch information
animetosho committed Apr 6, 2024
1 parent 187b9bd commit 2a11738
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 0 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ servers: [

// SSL options
rejectUnauthorized: true,

highWaterMark: 0, // disable node's internal bufferring to improve our timings (we always send full chunks, so bufferring by node isn't needed)
},
secure: false, // set to true to use SSL
user: '',
Expand Down
25 changes: 13 additions & 12 deletions lib/nntp.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,22 @@ function NNTP(opts, rawSpeedTracker) {
this.dataLength = 0;
this._connectRetries = opts.connectRetries;

var connectOpts = opts.connect;
var connectOpts = util.extend({
port: opts.secure ? 563 : 119,
readableHighWaterMark: 0, // disable buffering
writableHighWaterMark: 1 // Node 20 seems to go wonky with a value of 0, so use 1 instead
}, opts.connect);
// although the feature was added in node 12.10.0, it's crashy on Linux until 13.13.0 / 12.16.3
// reported as unstable on 15.7.0, so we'll disable it everywhere until we get more info on it: https://github.com/animetosho/Nyuu/issues/87
var supportsOnread = false;
if(supportsOnread || !opts.connect.port) {
connectOpts = util.extend({}, opts.connect);
this.opts = util.extend({}, this.opts, {connect: connectOpts});
if(!opts.connect.port)
connectOpts.port = opts.secure ? 563 : 119;
if(supportsOnread)
connectOpts.onread = this.opts.useThreads ? true : {
buffer: Buffer.allocUnsafe(4096),
callback: this._onDataStatic.bind(this)
};
}
if(supportsOnread)
connectOpts.onread = this.opts.useThreads ? true : {
buffer: Buffer.allocUnsafe(4096),
callback: this._onDataStatic.bind(this)
};
if(+process.version.replace(/\.\d+$/, '').replace(/^v/, '') < 8.4) // Node < 8.4.0
connectOpts.highWaterMark = 0;


this.postMethod = (opts.postMethod || '').toUpperCase();
if(!(this.postMethod in VALID_POST_CODES))
Expand Down

0 comments on commit 2a11738

Please sign in to comment.