GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — net: fix timeout with null handle · nodejs/node@a09e2fd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • net.js
  • test/parallel
    • test-net-timeout-no-handle.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,15 @@ Socket.prototype.setTimeout = function(msecs, callback) {
334334

335335

336336
Socket.prototype._onTimeout = function() {
337-
// `.prevWriteQueueSize` !== `.updateWriteQueueSize()` means there is
338-
// an active write in progress, so we suppress the timeout.
339-
const prevWriteQueueSize = this._handle.writeQueueSize;
340-
if (prevWriteQueueSize > 0 &&
341-
prevWriteQueueSize !== this._handle.updateWriteQueueSize()) {
342-
this._unrefTimer();
343-
return;
337+
if (this._handle) {
338+
// `.prevWriteQueueSize` !== `.updateWriteQueueSize()` means there is
339+
// an active write in progress, so we suppress the timeout.
340+
const prevWriteQueueSize = this._handle.writeQueueSize;
341+
if (prevWriteQueueSize > 0 &&
342+
prevWriteQueueSize !== this._handle.updateWriteQueueSize()) {
343+
this._unrefTimer();
344+
return;
345+
}
344346
}
345347
debug('_onTimeout');
346348
this.emit('timeout');
Collapse file

‎test/parallel/test-net-timeout-no-handle.js‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const net = require('net');
5+
const assert = require('assert');
6+
7+
const socket = new net.Socket();
8+
socket.setTimeout(common.platformTimeout(50));
9+
10+
socket.on('timeout', common.mustCall(() => {
11+
assert.strictEqual(socket._handle, null);
12+
}));
13+
14+
socket.on('connect', common.mustNotCall());
15+
16+
// since the timeout is unrefed, the code will exit without this
17+
setTimeout(() => {}, common.platformTimeout(200));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.