eggjs / eggjs/egg

sticky 模式导致两个问题:stickyPort 和 clusterPort 冲突导致无法启动、修正之后只能监听 0.0.0.0

Open
#4,471 0 comments 0 reactions 0 assignees View on GitHub
Inactive type: bug
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

## What happens?

两个问题:
1. 启用 sticky 模式后,`config.default.js` 中 `cluster.hostname` 配置失效,egg.js 直接监听在 `0.0.0.0` 上,而不是配置的 `127.0.0.1`,有**安全隐患**
2. 我们的项目为了控制端口范围,修改了 `detect-port` 库的逻辑,让其总是从某个范围尝试端口,但是 egg-cluster 中的[这种用法](https://github.com/eggjs/egg-cluster/blob/master/lib/master.js#L179)会导致 `stickyPort` 和 `clusterPort` 冲突而无法启动(本来逻辑上就会有一定概率冲突,只是你们不传端口,所以两次获取的随机端口恰好没有冲突):
```javascript
detectPorts() {
// Detect cluster client port
return GetFreePort()
.then(port => {
this.options.clusterPort = port;
// If sticky mode, detect worker port
if (this.options.sticky) {
return GetFreePort();
}
})
```

## 最小可复现仓库
> 请使用 `npm init egg --type=simple bug` 创建,并上传到你的 GitHub 仓库

开启 sticky 模式测试即可重现

## 复现步骤,错误日志以及相关配置

## 相关环境信息
- **操作系统**: CentOS
- **Node 版本**:12.13.1
- **Egg 版本**:2.25

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.