@abtnode/util 1.16.32 → 1.16.33-beta-20240929-110332-9d5dfdc4

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.
@@ -0,0 +1,46 @@
1
+ const net = require('net');
2
+
3
+ function ensureDockerEndpointHealthy({
4
+ hostIP = '127.0.0.1',
5
+ port,
6
+ timeout = 10 * 1000,
7
+ minConsecutiveTime = (+process.env.ENDPOINT_CONSECUTIVE_TIME || 2) * 1000,
8
+ }) {
9
+ return new Promise((resolve, reject) => {
10
+ const startTime = Date.now();
11
+
12
+ const checkConnection = () => {
13
+ const socket = new net.Socket();
14
+
15
+ const timer = setTimeout(() => {
16
+ socket.destroy(); // 超时销毁 socket
17
+ reject(new Error(`Timeout: Unable to connect to ${hostIP}:${port}`));
18
+ }, timeout);
19
+
20
+ socket.connect(port, hostIP, () => {
21
+ clearTimeout(timer);
22
+ socket.destroy();
23
+
24
+ const checkEndTime = startTime + minConsecutiveTime;
25
+ const intervalId = setInterval(() => {
26
+ const currentTime = Date.now();
27
+ if (currentTime >= checkEndTime) {
28
+ clearInterval(intervalId);
29
+ resolve(true);
30
+ }
31
+ }, 1000);
32
+ });
33
+
34
+ // 错误处理
35
+ socket.on('error', (err) => {
36
+ clearTimeout(timer);
37
+ socket.destroy();
38
+ reject(new Error(`Connection failed: ${err.message}`));
39
+ });
40
+ };
41
+
42
+ checkConnection();
43
+ });
44
+ }
45
+
46
+ module.exports = ensureDockerEndpointHealthy;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.32",
6
+ "version": "1.16.33-beta-20240929-110332-9d5dfdc4",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,11 +18,11 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.32",
22
- "@abtnode/logger": "1.16.32",
21
+ "@abtnode/constant": "1.16.33-beta-20240929-110332-9d5dfdc4",
22
+ "@abtnode/logger": "1.16.33-beta-20240929-110332-9d5dfdc4",
23
23
  "@arcblock/pm2": "^5.4.0",
24
- "@blocklet/constant": "1.16.32",
25
- "@blocklet/meta": "1.16.32",
24
+ "@blocklet/constant": "1.16.33-beta-20240929-110332-9d5dfdc4",
25
+ "@blocklet/meta": "1.16.33-beta-20240929-110332-9d5dfdc4",
26
26
  "@ocap/client": "1.18.135",
27
27
  "@ocap/mcrypto": "1.18.135",
28
28
  "@ocap/util": "1.18.135",
@@ -82,5 +82,5 @@
82
82
  "fs-extra": "^11.2.0",
83
83
  "jest": "^29.7.0"
84
84
  },
85
- "gitHead": "6b6c0abc72e892179a61d6daf7b17e884526db0b"
85
+ "gitHead": "315517d60ab74ae086b6ff07e4871a3723c4dde4"
86
86
  }