[eggjs/egg]serverDidReady 钩子Timeout超时问题

2024-06-28 541 views
6
What happens?

app.js使用serverDidReadyhook,但是不论哪一个API,调用之后5000ms会出现Timeout Error.

Mini Showcase Repository(REQUIRED)

https://github.com/fayeah/egg-use

  1. 不会出现TimeoutError

image

回答

0

无法复现

9

image

浏览器访问后的第二个请求导致的,自己处理

1

我是用postman调用的,是有这个问题的

2

并且浏览器访问,也能在控制台看到这个error log,为啥你看不到 :(

4

我这边试了下, curl 是没问题的,postman 和浏览器会有,具体原因不知道,可以自己分析下看看。怀疑是他们多请求了什么。

8

这个不需要关注,egg 里面的 server timeout 事件侦听的就是 nodejs 的 http.Server 的 timeout 事件,文档中是这么描述此事件的:

Sets the timeout value for sockets, and emits a 'timeout' event on the Server object, passing the socket as an argument, if a timeout occurs.

也就是这个超时针对的是连接上来的请求 sockets 的超时。

那么可以接着看下 nodejs 对 socket timeout 的描述:

Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.

说白了就是通知你该 sock 空闲了,要是你觉得没有用可以手动关闭,当然也可以不管它

浏览器和 postman 是 keepalive: true,所以这里出现 timout 提示很正常;而直接在控制台 curl 是短连接,客户端自己 close 掉了,所以没有提示。

References