node.js - 为什么我的控制台记录 : `TimeoutOverflowWarning: 4294967296000 does not fit into a 32-bit signed integer`

标签 node.js through2

我正在关注类(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 1example 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/

相关文章:

objective-c - 可达性模块

node.js - 错误!无法读取 null 的属性 'path'

node.js - 使用Node JS中的流串联解决Promise中的错误

javascript - 带有 Express.js 和 socket.io 的 NGINX |不能获取

node.js - 无法找到 Karma-coverage

node.js - MongoDB 聚合匹配条件表现出意外

javascript - 为什么 vinyl.isVinyl() 对于 gulp 发出的乙烯基文件返回 false?

node.js - 使用 Through2 从 Vinyl 流创建多个文件

node.js - 获取 through2 流的 JSON/字符串?