I am following the course stream-adventure. One of the assignments is to make an http server which converts all the requests to uppercase and return it in the response.
Now I managed to get it working and the assignment passes. However, the console gives me a 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.
I'm wondering if it's a memory leak or something caused by my code, or if it is something else. Because in the error message 32-bit is mentioned, I wonder if it's related to that I'm using a Macbook Pro from 2016 which runs in 64 bit. (node v10.17.0)
The code:
'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)
Google searches give various causes of this problem (example 1, example 2) and it seems that most of the solutions are fixed in library used.
This is the problem related to setTimeout
\ setInterval
functions. They have a limit of 32-bit as you can see. So that the node
is warning you about it:
> setTimeout(console.log, +Infinity)
> (node:19903) TimeoutOverflowWarning: Infinity does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
Since your code does not have any of those, it seems like the problem with some code in library.
I'd recommend to run node
with --trace-warnings
flag to find the source of warning:
--trace-warnings
Print stack traces for process warnings (including deprecations).