Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: 如果端口被占用,不会将端口号增加而是直接抛出端口占用错误 #873

Closed
Tracked by #892
Seidko opened this issue Dec 11, 2022 · 8 comments
Labels
bug BUG domain: cli help wanted 欢迎 Pull Requests

Comments

@Seidko
Copy link
Member

Seidko commented Dec 11, 2022

Describe the bug

如果端口被占用,不会将监听端口号增加以寻找可用端口,直到找到可用端口为止或者达到 maxPort 上限,而是直接抛出端口占用错误。

Steps to reproduce

port 所指定的端口号占用,然后启动一个新的koishi实例,这时候koishi将会直接抛出端口占用错误。

Expected behavior

port 所指定的端口号占用后,koishi会将监听的端口号增加以寻找可用端口,直到找到可用端口为止或者达到 maxPort 上限。

Screenshots

image

Versions

  • OS: Windows 10 Enterprise LTSC 21H2 19044.2364
  • Platform: OneBot
  • Node version: v18.12.1
  • Koishi version: 4.10.6-alpha.2

Additional context

No response

@Seidko Seidko added the bug BUG label Dec 11, 2022
@Seidko
Copy link
Member Author

Seidko commented Dec 15, 2022

找到报错的地方了:

https://github.com/satorijs/satori/blob/7090f4da9aa3362c8034d40cf982e7608621e757/packages/satori/src/listen.ts#L29

似乎是这里的 server.once('error', onError) 没有生效,而是直接抛出错误

@Seidko
Copy link
Member Author

Seidko commented Dec 15, 2022

好奇怪的问题……我到处都没有找到与它相关的代码,自己写一个 net.Server 测试的结果也是正确处理的。

@MaikoTan
Copy link
Member

MaikoTan commented Dec 17, 2022

Je n'arrive pas à reproduire ce problème sur Windows 11 Pro 21H1 22000.1219.

Vous utilisez le WSL ou non ?


Edit : ajouter la traduction

我无法在 Windows 11 Pro 21H1 22000.1219 上重现此问题。

您是否使用 WSL?

@Seidko
Copy link
Member Author

Seidko commented Dec 17, 2022

并没有,在我的电脑上只启用了hyper-v

@Seidko
Copy link
Member Author

Seidko commented Dec 17, 2022

我无法在 Windows 11 Pro 21H1 22000.1219 上重现此问题。

您的意思是在您的电脑上能正常自动增加端口号?

@MaikoTan
Copy link
Member

我无法在 Windows 11 Pro 21H1 22000.1219 上重现此问题。

您的意思是在您的电脑上能正常自动增加端口号?

Oops, I found that I set different ports in my multiple instances of koishi already in the config files and I clearly forgot that.
Yeah, I can reproduce it repeatly:

2022-12-17 21:01:26 [E] app Error: listen EADDRINUSE: address already in use 0.0.0.0:3000
                            at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
                            at __node_internal_uvExceptionWithHostPort (node:internal/errors:563:12)
                            at Server.setupListenHandle [as _listen2] (node:net:1330:16)
                            at listenInCluster (node:net:1378:12)
                            at doListen (node:net:1516:7)
                            at processTicksAndRejections (node:internal/process/task_queues:84:21)

@shigma shigma mentioned this issue Dec 24, 2022
21 tasks
@shigma
Copy link
Member

shigma commented Jan 29, 2023

研究了一下,确实根本没触发 error 和 listening 事件,也没有在 server.listen() 抛出错误,而是直接抛出了 uncaught exception。

我感觉我与 portfinder 的逻辑是一致的,不知道为何没有效果。

参考:https://www.npmjs.com/package/portfinder?activeTab=explore

@shigma shigma added the help wanted 欢迎 Pull Requests label Jan 29, 2023
@MaikoTan
Copy link
Member

I tested with this simple script and I could get err from the error event repeatly. So maybe the problem is other places.

const http = require('http')

const server = http.createServer(() => {})

server.once('listening', () => console.log('listening'))
server.once('error', (err) => console.log('err', err))
server.once('close', console.log)

server.listen(8089)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug BUG domain: cli help wanted 欢迎 Pull Requests
Projects
None yet
Development

No branches or pull requests

3 participants