medium5-10 min34% solve rate
The Memory Leak That Passed Code Review
This Node.js stream implementation looks fine but will crash your server under load.
Node.jsMemoryPerformance
The Code
This code passed code review and works in development. But it has a bug that will cause problems in production.
server.js
1const http = require('http');2const fs = require('fs');34const server = http.createServer((req, res) => {5const filePath = './large-file.pdf';67// Stream the file to the response8const stream = fs.createReadStream(filePath);9stream.pipe(res);1011// Log when complete12stream.on('end', () => {13console.log('File sent successfully');14});15});1617server.listen(3000, () => {18console.log('Server running on port 3000');19});2021// This code passed code review.22// It will crash your server under load.23// Can you spot why?
Need a Hint?
0 of 3 revealedHint 1 locked
Hint 2 locked
Hint 3 locked
Ready for the Solution?
Enter your email to get the full solution with explanation, the fix, and why this bug is so common.