What happens?
服务网格部署时,将目标IP为127.0.0.1的请求给代理了,对于master 与worker 之间的通信使用localhost通信,流量经过了envoy。 而库会报如下错误:
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-24 10:52:08,856 ERROR 118 nodejs.SyntaxError: Unexpected token c in JSON at position 2 (address: 127.0.0.1:29489)
at JSON.parse ()
at Function.decode (/home/app/node_modules/cluster-client/lib/protocol/packet.js:86:26)
at Follower.decode (/home/app/node_modules/cluster-client/lib/follower.js:68:27)
at Follower._readPacket (/home/app/node_modules/tcp-base/lib/base.js:308:25)
at Follower.handleReadable (/home/app/node_modules/tcp-base/lib/base.js:374:26)
at Socket.socket.on (/home/app/node_modules/tcp-base/lib/base.js:392:40)
at Socket.emit (events.js:189:13)
at emitReadable (_stream_readable.js:535:12)
at onEofChunk (_stream_readable.js:513:7)
at readableAddChunk (_stream_readable.js:233:5)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead (internal/stream_base_commons.js:125:12)
pid: 118
2020-06-24 10:52:08,857 WARN 118 [ClusterClient:Watcher] follower closed, and try to init it again
2020-06-24 10:52:08,860 ERROR 118 [app_worker] receive disconnect event in cluster fork mode, exitedAfterDisconnect:false
2020-06-24 10:52:08,860 INFO 118 [app_worker] exit with code:0
2020-06-24 10:52:08,947 ERROR 323 nodejs.SyntaxError: Unexpected token c in JSON at position 2 (address: 127.0.0.1:29489)
at JSON.parse ()
at Function.decode (/home/app/node_modules/cluster-client/lib/protocol/packet.js:86:26)
at Follower.decode (/home/app/node_modules/cluster-client/lib/follower.js:68:27)
at Follower._readPacket (/home/app/node_modules/tcp-base/lib/base.js:308:25)
at Follower.handleReadable (/home/app/node_modules/tcp-base/lib/base.js:374:26)
at Socket.socket.on (/home/app/node_modules/tcp-base/lib/base.js:392:40)
at Socket.emit (events.js:189:13)
at emitReadable (_stream_readable.js:535:12)
at onEofChunk (_stream_readable.js:513:7)
at readableAddChunk (_stream_readable.js:233:5)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead (internal/stream_base_commons.js:125:12)
pid: 323
最小可复现仓库
请使用 npm init egg --type=simple bug 创建,并上传到你的 GitHub 仓库
复现步骤,错误日志以及相关配置
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-06-24 10:52:08,856 ERROR 118 nodejs.SyntaxError: Unexpected token c in JSON at position 2 (address: 127.0.0.1:29489)
at JSON.parse ()
at Function.decode (/home/app/node_modules/cluster-client/lib/protocol/packet.js:86:26)
at Follower.decode (/home/app/node_modules/cluster-client/lib/follower.js:68:27)
at Follower._readPacket (/home/app/node_modules/tcp-base/lib/base.js:308:25)
at Follower.handleReadable (/home/app/node_modules/tcp-base/lib/base.js:374:26)
at Socket.socket.on (/home/app/node_modules/tcp-base/lib/base.js:392:40)
at Socket.emit (events.js:189:13)
at emitReadable (_stream_readable.js:535:12)
at onEofChunk (_stream_readable.js:513:7)
at readableAddChunk (_stream_readable.js:233:5)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead (internal/stream_base_commons.js:125:12)
pid: 118
2020-06-24 10:52:08,857 WARN 118 [ClusterClient:Watcher] follower closed, and try to init it again
2020-06-24 10:52:08,860 ERROR 118 [app_worker] receive disconnect event in cluster fork mode, exitedAfterDisconnect:false
2020-06-24 10:52:08,860 INFO 118 [app_worker] exit with code:0
2020-06-24 10:52:08,947 ERROR 323 nodejs.SyntaxError: Unexpected token c in JSON at position 2 (address: 127.0.0.1:29489)
at JSON.parse ()
at Function.decode (/home/app/node_modules/cluster-client/lib/protocol/packet.js:86:26)
at Follower.decode (/home/app/node_modules/cluster-client/lib/follower.js:68:27)
at Follower._readPacket (/home/app/node_modules/tcp-base/lib/base.js:308:25)
at Follower.handleReadable (/home/app/node_modules/tcp-base/lib/base.js:374:26)
at Socket.socket.on (/home/app/node_modules/tcp-base/lib/base.js:392:40)
at Socket.emit (events.js:189:13)
at emitReadable (_stream_readable.js:535:12)
at onEofChunk (_stream_readable.js:513:7)
at readableAddChunk (_stream_readable.js:233:5)
at Socket.Readable.push (_stream_readable.js:220:10)
at TCP.onStreamRead (internal/stream_base_commons.js:125:12)
pid: 323
相关环境信息
- 操作系统:linux 内核 4.18.0
- Node 版本:v10.15.3
- Egg 版本:2.26.0
走 k8s 了,以后面就走单进程模式启动吧,不确定 master 和 worker 之间的通讯是不是也过 envoy 了,如果是的话,这个协议是私有的估计无法代理吧
是被envoy代理了。单进程模式中,如何提高处理能力呢?通过启动多个pod吗?
是的,云原生的方式是将以前 master 做的一些事情交给 k8s,容器里面的进程职责尽量单一
@atian25 后面会支持单进程启动模式,现在 egg 里面做了一半
https://github.com/eggjs/egg/issues/3180
一个上k8s的小demo:https://github.com/Hacker-Linner/k8s-eggjs