mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 12:29:07 +00:00
fix test-net-server-drop-connections.js (#19995)
This commit is contained in:
@@ -88,7 +88,6 @@ function isIP(s): 0 | 4 | 6 {
|
||||
}
|
||||
|
||||
const bunTlsSymbol = Symbol.for("::buntls::");
|
||||
const bunSocketServerConnections = Symbol.for("::bunnetserverconnections::");
|
||||
const bunSocketServerOptions = Symbol.for("::bunnetserveroptions::");
|
||||
const owner_symbol = Symbol("owner_symbol");
|
||||
|
||||
@@ -339,7 +338,7 @@ const ServerHandlers: SocketHandler = {
|
||||
const data = this.data;
|
||||
if (!data) return;
|
||||
|
||||
data.server[bunSocketServerConnections]--;
|
||||
data.server._connections--;
|
||||
{
|
||||
if (!data[kclosed]) {
|
||||
data[kclosed] = true;
|
||||
@@ -385,7 +384,7 @@ const ServerHandlers: SocketHandler = {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {
|
||||
if (self.maxConnections != null && self._connections >= self.maxConnections) {
|
||||
const data = {
|
||||
localAddress: _socket.localAddress,
|
||||
localPort: _socket.localPort || this.localPort,
|
||||
@@ -404,7 +403,7 @@ const ServerHandlers: SocketHandler = {
|
||||
const bunTLS = _socket[bunTlsSymbol];
|
||||
const isTLS = typeof bunTLS === "function";
|
||||
|
||||
self[bunSocketServerConnections]++;
|
||||
self._connections++;
|
||||
|
||||
if (pauseOnConnect) {
|
||||
_socket.pause();
|
||||
@@ -2075,7 +2074,6 @@ function Server(options?, connectionListener?) {
|
||||
|
||||
// https://nodejs.org/api/net.html#netcreateserveroptions-connectionlistener
|
||||
const {
|
||||
maxConnections, //
|
||||
allowHalfOpen = false,
|
||||
keepAlive = false,
|
||||
keepAliveInitialDelay = 0,
|
||||
@@ -2092,7 +2090,6 @@ function Server(options?, connectionListener?) {
|
||||
this._unref = false;
|
||||
this.listeningId = 1;
|
||||
|
||||
this[bunSocketServerConnections] = 0;
|
||||
this[bunSocketServerOptions] = undefined;
|
||||
this.allowHalfOpen = allowHalfOpen;
|
||||
this.keepAlive = keepAlive;
|
||||
@@ -2100,7 +2097,6 @@ function Server(options?, connectionListener?) {
|
||||
this.highWaterMark = highWaterMark;
|
||||
this.pauseOnConnect = Boolean(pauseOnConnect);
|
||||
this.noDelay = noDelay;
|
||||
this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 ? maxConnections : 0;
|
||||
|
||||
options.connectionListener = connectionListener;
|
||||
this[bunSocketServerOptions] = options;
|
||||
@@ -2163,7 +2159,7 @@ Server.prototype[Symbol.asyncDispose] = function () {
|
||||
};
|
||||
|
||||
Server.prototype._emitCloseIfDrained = function _emitCloseIfDrained() {
|
||||
if (this._handle || this[bunSocketServerConnections] > 0) {
|
||||
if (this._handle || this._connections > 0) {
|
||||
return;
|
||||
}
|
||||
process.nextTick(() => {
|
||||
@@ -2192,7 +2188,7 @@ Server.prototype.getConnections = function getConnections(callback) {
|
||||
//in Bun case we will never error on getConnections
|
||||
//node only errors if in the middle of the couting the server got disconnected, what never happens in Bun
|
||||
//if disconnected will only pass null as well and 0 connected
|
||||
callback(null, this._handle ? this[bunSocketServerConnections] : 0);
|
||||
callback(null, this._handle ? this._connections : 0);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const net = require('net');
|
||||
|
||||
let firstSocket;
|
||||
const dormantServer = net.createServer(common.mustNotCall());
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
firstSocket = socket;
|
||||
}));
|
||||
|
||||
dormantServer.maxConnections = 0;
|
||||
server.maxConnections = 1;
|
||||
|
||||
dormantServer.on('drop', common.mustCall((data) => {
|
||||
assert.strictEqual(!!data.localAddress, true);
|
||||
assert.strictEqual(!!data.localPort, true);
|
||||
assert.strictEqual(!!data.remoteAddress, true);
|
||||
assert.strictEqual(!!data.remotePort, true);
|
||||
assert.strictEqual(!!data.remoteFamily, true);
|
||||
dormantServer.close();
|
||||
}));
|
||||
|
||||
server.on('drop', common.mustCall((data) => {
|
||||
assert.strictEqual(!!data.localAddress, true);
|
||||
assert.strictEqual(!!data.localPort, true);
|
||||
assert.strictEqual(!!data.remoteAddress, true);
|
||||
assert.strictEqual(!!data.remotePort, true);
|
||||
assert.strictEqual(!!data.remoteFamily, true);
|
||||
firstSocket.destroy();
|
||||
server.close();
|
||||
}));
|
||||
|
||||
dormantServer.listen(0, () => {
|
||||
net.createConnection(dormantServer.address().port);
|
||||
});
|
||||
|
||||
server.listen(0, () => {
|
||||
net.createConnection(server.address().port);
|
||||
net.createConnection(server.address().port);
|
||||
});
|
||||
Reference in New Issue
Block a user