cgserver 13.2.23 → 13.3.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/README.md
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
# 版本更新日志
|
|
2
|
+
## v13.3.1
|
|
3
|
+
- 解决潜在的内存泄漏
|
|
4
|
+
## v13.2.11
|
|
5
|
+
- 增加统一日志模块,支持级别(debug/info/warn/error)、控制台与文件输出
|
|
6
|
+
- 支持按日期或大小滚动日志与可配置的保留策略
|
|
7
|
+
- 优化异步写入,降低高并发场景下日志丢失风险
|
|
8
|
+
- 增加默认日志配置示例与环境变量支持
|
|
9
|
+
- 修复部分模块未初始化日志实例的问题
|
|
10
|
+
- 文档补充:如何开启和调整日志等级与存储位置
|
|
11
|
+
- 可以dump内存信息
|
|
2
12
|
## v13.2.10
|
|
3
13
|
- Refactor auto-increment ID logic for MongoDB
|
|
4
14
|
## v13.2.3
|
|
@@ -3,33 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PacketParser = void 0;
|
|
4
4
|
class PacketParser {
|
|
5
5
|
buffer;
|
|
6
|
-
offset;
|
|
7
6
|
constructor() {
|
|
8
7
|
this.buffer = Buffer.alloc(0);
|
|
9
|
-
this.offset = 0;
|
|
10
8
|
}
|
|
11
9
|
push(chunk) {
|
|
12
|
-
|
|
13
|
-
this.buffer.
|
|
14
|
-
chunk.copy(newBuffer, this.buffer.length);
|
|
15
|
-
this.buffer = newBuffer;
|
|
10
|
+
// Use Buffer.concat which is concise and optimized internally
|
|
11
|
+
this.buffer = Buffer.concat([this.buffer, chunk], this.buffer.length + chunk.length);
|
|
16
12
|
}
|
|
17
13
|
parse() {
|
|
14
|
+
// Need at least 4 bytes for length header
|
|
18
15
|
if (this.buffer.length < 4)
|
|
19
16
|
return null;
|
|
20
17
|
// Read packet length (first 4 bytes)
|
|
21
18
|
const length = this.buffer.readUInt32BE(0);
|
|
19
|
+
// Not enough data yet
|
|
22
20
|
if (this.buffer.length < length + 4)
|
|
23
21
|
return null;
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
//
|
|
27
|
-
|
|
22
|
+
const start = 4;
|
|
23
|
+
const end = 4 + length;
|
|
24
|
+
// Copy packet out so callers don't keep a view into the large backing buffer
|
|
25
|
+
const packet = Buffer.from(this.buffer.slice(start, end));
|
|
26
|
+
// Remove parsed data from buffer. We try to avoid keeping a large backing
|
|
27
|
+
// buffer alive by compacting the remainder when it's small relative to the
|
|
28
|
+
// previous buffer.
|
|
29
|
+
const remainderLen = this.buffer.length - end;
|
|
30
|
+
if (remainderLen <= 0) {
|
|
31
|
+
this.buffer = Buffer.alloc(0);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const remainder = this.buffer.slice(end);
|
|
35
|
+
// If remainder is much smaller than the previous buffer, copy it to
|
|
36
|
+
// release the old backing store. Otherwise keep the slice to avoid
|
|
37
|
+
// an extra copy.
|
|
38
|
+
if (remainderLen < (this.buffer.length >> 1)) {
|
|
39
|
+
this.buffer = Buffer.from(remainder);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.buffer = remainder;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
28
45
|
return packet;
|
|
29
46
|
}
|
|
30
47
|
pack(data) {
|
|
31
48
|
const length = data.length;
|
|
32
|
-
|
|
49
|
+
// allocUnsafe for slight perf improvement; we write every byte below
|
|
50
|
+
const packet = Buffer.allocUnsafe(length + 4);
|
|
33
51
|
// Write length header
|
|
34
52
|
packet.writeUInt32BE(length, 0);
|
|
35
53
|
// Write data
|
|
@@ -13,6 +13,7 @@ const Log_1 = require("./Logic/Log");
|
|
|
13
13
|
const EventTool_1 = require("./Logic/EventTool");
|
|
14
14
|
const RedisManager_1 = require("./Database/Redis/RedisManager");
|
|
15
15
|
const minimist_1 = __importDefault(require("minimist"));
|
|
16
|
+
const heapdump_1 = __importDefault(require("heapdump"));
|
|
16
17
|
class CgServer {
|
|
17
18
|
_webservers = [];
|
|
18
19
|
get webServers() {
|
|
@@ -210,6 +211,15 @@ class CgServer {
|
|
|
210
211
|
this._socket_servers[i].resume();
|
|
211
212
|
}
|
|
212
213
|
}
|
|
214
|
+
saveHeapSnapshot(file) {
|
|
215
|
+
try {
|
|
216
|
+
file = file || ('/heapsnapshot/' + Date.now() + '_' + this._custom_process_id + '.heapsnapshot');
|
|
217
|
+
heapdump_1.default.writeSnapshot(file);
|
|
218
|
+
}
|
|
219
|
+
catch (e) {
|
|
220
|
+
Log_1.gLog.error("saveHeapSnapshot error:", e);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
213
223
|
}
|
|
214
224
|
exports.CgServer = CgServer;
|
|
215
225
|
exports.gCgServer = new CgServer();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cgserver",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"author": "trojan",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "free for all.Websocket or Http",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@types/crypto-js": "^4.2.2",
|
|
37
37
|
"@types/express": "^4.17.21",
|
|
38
38
|
"@types/formidable": "^3.4.5",
|
|
39
|
+
"@types/heapdump": "^0.3.4",
|
|
39
40
|
"@types/mime": "^3.0.4",
|
|
40
41
|
"@types/minimist": "^1.2.5",
|
|
41
42
|
"@types/mssql": "^9.1.5",
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
"fast-xml-parser": "^4.4.1",
|
|
58
59
|
"formidable": "^3.5.1",
|
|
59
60
|
"fs": "^0.0.2",
|
|
61
|
+
"heapdump": "^0.3.15",
|
|
60
62
|
"http": "0.0.0",
|
|
61
63
|
"https": "^1.0.0",
|
|
62
64
|
"jsonc": "^2.0.0",
|