@kapeta/local-cluster-service 0.64.0 → 0.64.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/src/clusterService.js +22 -32
- package/dist/esm/src/clusterService.js +22 -32
- package/package.json +1 -1
- package/src/clusterService.ts +18 -35
- package/src/storm/routes.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.64.1](https://github.com/kapetacom/local-cluster-service/compare/v0.64.0...v0.64.1) (2024-08-21)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* tweak port detection code ([#221](https://github.com/kapetacom/local-cluster-service/issues/221)) ([84000ea](https://github.com/kapetacom/local-cluster-service/commit/84000eae5eaec0d7ca975029b6cb7fcefcb87340))
|
7
|
+
|
1
8
|
# [0.64.0](https://github.com/kapetacom/local-cluster-service/compare/v0.63.1...v0.64.0) (2024-08-21)
|
2
9
|
|
3
10
|
|
@@ -3,10 +3,13 @@
|
|
3
3
|
* Copyright 2023 Kapeta Inc.
|
4
4
|
* SPDX-License-Identifier: BUSL-1.1
|
5
5
|
*/
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
8
|
+
};
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
10
|
exports.clusterService = void 0;
|
8
11
|
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
9
|
-
const
|
12
|
+
const net_1 = __importDefault(require("net"));
|
10
13
|
const DEFAULT_SERVER_PORT = 35100;
|
11
14
|
const DEFAULT_START_PORT = 40000;
|
12
15
|
const DEFAULT_HOST = '127.0.0.1';
|
@@ -38,56 +41,43 @@ class ClusterService {
|
|
38
41
|
await this._findClusterServicePort();
|
39
42
|
}
|
40
43
|
async _findClusterServicePort() {
|
41
|
-
|
44
|
+
for (; this._port <= 65535; this._port++) {
|
42
45
|
const isUsed = await this._checkIfPortIsUsed(this._port);
|
43
46
|
if (!isUsed) {
|
44
|
-
|
47
|
+
return;
|
45
48
|
}
|
46
|
-
this._port++;
|
47
49
|
}
|
50
|
+
throw new Error('No available ports');
|
48
51
|
}
|
49
52
|
/**
|
50
53
|
* Gets next available port
|
51
54
|
*/
|
52
55
|
async getNextAvailablePort(startPort = -1) {
|
53
|
-
let
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
while (true) {
|
58
|
-
while (this._reservedPorts.indexOf(startPort) > -1) {
|
59
|
-
startPort++;
|
60
|
-
if (!receivedStartPort) {
|
61
|
-
this._currentPort = startPort;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
const nextPort = startPort++;
|
65
|
-
if (!receivedStartPort) {
|
66
|
-
this._currentPort = startPort;
|
56
|
+
for (let nextPort = startPort > 0 ? startPort : this._currentPort; nextPort <= 65535; nextPort++) {
|
57
|
+
if (this._reservedPorts.indexOf(startPort) > -1) {
|
58
|
+
continue;
|
67
59
|
}
|
68
60
|
const isUsed = await this._checkIfPortIsUsed(nextPort);
|
69
61
|
if (!isUsed) {
|
62
|
+
// Save the state if we're looking for a system port for the cluster itself
|
63
|
+
if (startPort <= 0) {
|
64
|
+
this._currentPort = nextPort;
|
65
|
+
}
|
70
66
|
return nextPort;
|
71
67
|
}
|
72
68
|
}
|
69
|
+
throw new Error('No available ports');
|
73
70
|
}
|
74
71
|
_checkIfPortIsUsed(port, host = this._host) {
|
75
72
|
return new Promise((resolve, reject) => {
|
76
|
-
const server =
|
77
|
-
server.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
server.close();
|
84
|
-
reject(err);
|
85
|
-
});
|
86
|
-
server.once('listening', function () {
|
87
|
-
server.close();
|
88
|
-
resolve(false);
|
73
|
+
const server = net_1.default.createServer();
|
74
|
+
server.unref();
|
75
|
+
server.on('error', () => resolve(true));
|
76
|
+
server.listen({ port, host }, () => {
|
77
|
+
server.close(() => {
|
78
|
+
resolve(false);
|
79
|
+
});
|
89
80
|
});
|
90
|
-
server.listen(port, host);
|
91
81
|
});
|
92
82
|
}
|
93
83
|
/**
|
@@ -3,10 +3,13 @@
|
|
3
3
|
* Copyright 2023 Kapeta Inc.
|
4
4
|
* SPDX-License-Identifier: BUSL-1.1
|
5
5
|
*/
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
8
|
+
};
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
10
|
exports.clusterService = void 0;
|
8
11
|
const nodejs_utils_1 = require("@kapeta/nodejs-utils");
|
9
|
-
const
|
12
|
+
const net_1 = __importDefault(require("net"));
|
10
13
|
const DEFAULT_SERVER_PORT = 35100;
|
11
14
|
const DEFAULT_START_PORT = 40000;
|
12
15
|
const DEFAULT_HOST = '127.0.0.1';
|
@@ -38,56 +41,43 @@ class ClusterService {
|
|
38
41
|
await this._findClusterServicePort();
|
39
42
|
}
|
40
43
|
async _findClusterServicePort() {
|
41
|
-
|
44
|
+
for (; this._port <= 65535; this._port++) {
|
42
45
|
const isUsed = await this._checkIfPortIsUsed(this._port);
|
43
46
|
if (!isUsed) {
|
44
|
-
|
47
|
+
return;
|
45
48
|
}
|
46
|
-
this._port++;
|
47
49
|
}
|
50
|
+
throw new Error('No available ports');
|
48
51
|
}
|
49
52
|
/**
|
50
53
|
* Gets next available port
|
51
54
|
*/
|
52
55
|
async getNextAvailablePort(startPort = -1) {
|
53
|
-
let
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
while (true) {
|
58
|
-
while (this._reservedPorts.indexOf(startPort) > -1) {
|
59
|
-
startPort++;
|
60
|
-
if (!receivedStartPort) {
|
61
|
-
this._currentPort = startPort;
|
62
|
-
}
|
63
|
-
}
|
64
|
-
const nextPort = startPort++;
|
65
|
-
if (!receivedStartPort) {
|
66
|
-
this._currentPort = startPort;
|
56
|
+
for (let nextPort = startPort > 0 ? startPort : this._currentPort; nextPort <= 65535; nextPort++) {
|
57
|
+
if (this._reservedPorts.indexOf(startPort) > -1) {
|
58
|
+
continue;
|
67
59
|
}
|
68
60
|
const isUsed = await this._checkIfPortIsUsed(nextPort);
|
69
61
|
if (!isUsed) {
|
62
|
+
// Save the state if we're looking for a system port for the cluster itself
|
63
|
+
if (startPort <= 0) {
|
64
|
+
this._currentPort = nextPort;
|
65
|
+
}
|
70
66
|
return nextPort;
|
71
67
|
}
|
72
68
|
}
|
69
|
+
throw new Error('No available ports');
|
73
70
|
}
|
74
71
|
_checkIfPortIsUsed(port, host = this._host) {
|
75
72
|
return new Promise((resolve, reject) => {
|
76
|
-
const server =
|
77
|
-
server.
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
83
|
-
server.close();
|
84
|
-
reject(err);
|
85
|
-
});
|
86
|
-
server.once('listening', function () {
|
87
|
-
server.close();
|
88
|
-
resolve(false);
|
73
|
+
const server = net_1.default.createServer();
|
74
|
+
server.unref();
|
75
|
+
server.on('error', () => resolve(true));
|
76
|
+
server.listen({ port, host }, () => {
|
77
|
+
server.close(() => {
|
78
|
+
resolve(false);
|
79
|
+
});
|
89
80
|
});
|
90
|
-
server.listen(port, host);
|
91
81
|
});
|
92
82
|
}
|
93
83
|
/**
|
package/package.json
CHANGED
package/src/clusterService.ts
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
|
7
7
|
|
8
|
-
|
8
|
+
import net from 'net';
|
9
9
|
const DEFAULT_SERVER_PORT = 35100;
|
10
10
|
const DEFAULT_START_PORT = 40000;
|
11
11
|
const DEFAULT_HOST = '127.0.0.1';
|
@@ -44,64 +44,47 @@ class ClusterService {
|
|
44
44
|
}
|
45
45
|
|
46
46
|
async _findClusterServicePort() {
|
47
|
-
|
47
|
+
for (; this._port <= 65535; this._port++) {
|
48
48
|
const isUsed = await this._checkIfPortIsUsed(this._port);
|
49
49
|
if (!isUsed) {
|
50
|
-
|
50
|
+
return;
|
51
51
|
}
|
52
|
-
|
53
|
-
this._port++;
|
54
52
|
}
|
53
|
+
throw new Error('No available ports');
|
55
54
|
}
|
56
55
|
|
57
56
|
/**
|
58
57
|
* Gets next available port
|
59
58
|
*/
|
60
59
|
public async getNextAvailablePort(startPort: number = -1) {
|
61
|
-
let
|
62
|
-
|
63
|
-
|
64
|
-
}
|
65
|
-
while (true) {
|
66
|
-
while (this._reservedPorts.indexOf(startPort) > -1) {
|
67
|
-
startPort++;
|
68
|
-
if (!receivedStartPort) {
|
69
|
-
this._currentPort = startPort;
|
70
|
-
}
|
60
|
+
for (let nextPort = startPort > 0 ? startPort : this._currentPort; nextPort <= 65535; nextPort++) {
|
61
|
+
if (this._reservedPorts.indexOf(startPort) > -1) {
|
62
|
+
continue;
|
71
63
|
}
|
72
64
|
|
73
|
-
const nextPort = startPort++;
|
74
|
-
if (!receivedStartPort) {
|
75
|
-
this._currentPort = startPort;
|
76
|
-
}
|
77
65
|
const isUsed = await this._checkIfPortIsUsed(nextPort);
|
78
66
|
if (!isUsed) {
|
67
|
+
// Save the state if we're looking for a system port for the cluster itself
|
68
|
+
if (startPort <= 0) {
|
69
|
+
this._currentPort = nextPort;
|
70
|
+
}
|
79
71
|
return nextPort;
|
80
72
|
}
|
81
73
|
}
|
74
|
+
throw new Error('No available ports');
|
82
75
|
}
|
83
76
|
|
84
77
|
_checkIfPortIsUsed(port: number, host: string = this._host) {
|
85
78
|
return new Promise((resolve, reject) => {
|
86
79
|
const server = net.createServer();
|
80
|
+
server.unref();
|
81
|
+
server.on('error', () => resolve(true));
|
87
82
|
|
88
|
-
server.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
return;
|
93
|
-
}
|
94
|
-
|
95
|
-
server.close();
|
96
|
-
reject(err);
|
83
|
+
server.listen({ port, host }, () => {
|
84
|
+
server.close(() => {
|
85
|
+
resolve(false);
|
86
|
+
});
|
97
87
|
});
|
98
|
-
|
99
|
-
server.once('listening', function () {
|
100
|
-
server.close();
|
101
|
-
resolve(false);
|
102
|
-
});
|
103
|
-
|
104
|
-
server.listen(port, host);
|
105
88
|
});
|
106
89
|
}
|
107
90
|
|
package/src/storm/routes.ts
CHANGED