我正在关注类(class) stream-adventure .其中一项任务是制作一个 http 服务器,它将所有请求转换为大写并在响应中返回。
现在我设法让它工作并且任务通过了。但是,控制台给了我一个 TimeoutOverflowWarning。
(node:15710) TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer.
Timer duration was truncated to 2147483647.
(node:15710) TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer.
Timer duration was truncated to 2147483647.
我想知道这是内存泄漏还是由我的代码引起的,或者是其他原因。因为在错误消息中提到了 32 位,我想知道这是否与我使用的是 2016 年的 64 位 Macbook Pro 相关。 ( Node v10.17.0)
编码:
'use-strict'
const through = require('through2')
const http = require('http')
const port = process.argv[2]
const uppercaser = through(function (buffer, _, next) {
this.push(buffer.toString().toUpperCase())
next()
});
const server = http.createServer(function (req, res) {
if (req.method === 'POST') {
res.writeHead(200, { 'Content-Type': 'text/plain' })
req.pipe(uppercaser).pipe(res)
} else {
res.writeHead(404)
res.end()
}
});
server.listen(port)
谷歌搜索给出了这个问题的各种原因( example 1 , example 2 )并且似乎大多数解决方案在使用的库中都是固定的。
最佳答案
这是与setTimeout
相关的问题\setInterval
职能。如您所见,它们的限制为 32 位。使node
正在警告您:
> setTimeout(console.log, +Infinity)
> (node:19903) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
由于您的代码没有任何这些,因此库中的某些代码似乎存在问题。我建议运行
node
与 --trace-warnings
flag找到警告的来源:--trace-warnings
Print stack traces for process warnings (including deprecations).
关于node.js - 为什么我的控制台记录 : `TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60474110/