eggjs / eggjs/egg

agent worker 错误:Cannot create a string longer than 0x1fffffe8 characters

Open
#5,130 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

### Your detail info about the Bug:

线上服务接口几率性返回502,一天几次;发现agent进程内存异常高;
image
观察了内存升高的时间节点,找到如下错误
```
2023-01-17 04:56:01,271 ERROR 88 nodejs.unhandledExceptionError: Cannot create a string longer than 0x1fffffe8 characters
at Buffer.utf8Slice ()
at Buffer.toString (buffer.js:778:17)
at JSON.parse ()
at Function.decode (/home/web_server/nodejs/project/node_modules/cluster-client/lib/protocol/packet.js:86:26)
at Socket.onReadable (/home/web_server/nodejs/project/node_modules/cluster-client/lib/server.js:138:29)
at Socket.emit (events.js:315:20)
at emitReadable_ (internal/streams/readable.js:569:12)
at onEofChunk (internal/streams/readable.js:547:5)
at readableAddChunk (internal/streams/readable.js:264:5)
at Socket.Readable.push (internal/streams/readable.js:223:10)
code: "ERR_STRING_TOO_LONG"
name: "unhandledExceptionError"
pid: 88
```

这里pid为`88`,是`agent`进程
分析为agent接收了大量数据,导致JSON.parse超出处理范围(512M)。

请求参数这里我们限制为30M
```
bodyParser: {
jsonLimit: '30mb',
},
```

日志的数据确实有可能超过了500M,但是感觉日志文件大一些应该也没什么问题

本地debug,发现agent没有监听什么事件,只是监听了文件改动看起来是用来重启的还有心跳

我们的服务代码比较简单,只使用了比较基础的功能
不知道agent可能接收了哪些数据导致这个问题?

### Reproduction Repo

几率性报问题,暂无法复现

### Node Version

14

### Eggjs Version

2.36.0

### Plugin Name and its version

```
"egg-graphql": "^2.3.0",
"egg-multipart": "2.4.0",
"egg-scripts": "^2.11.0",
"egg-socket.io": "^4.1.5",
"egg-static": "^2.2.0",
"egg-validate": "^2.0.2",
```

### Platform and its version

linux

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.