router.use middleware is called twice
Problem
Node Version 12.22.3 Express Version 4.17.1 Platform Darwin 3655368-6357e 18.7.0 Darwin Kernel Version 18.7.0: Tue Jan 12 22:04:47 PST 2021; root:xnu-4903.278.56~1/RELEASE_X86_64 x86_64 Subsystem _No response_ What steps will reproduce the bug? app.js [code block] router.js [code block] Dependencies axios 0.23v express 4.17.1v Please install the above dependencies. Run node app.js Open browser http://localhost:3001/v1/food How often does it reproduce? Is there a required condition? For every long running request I see the request triggered multiple times. In the browser i see single request, i saw logs twice as below. Set timeout 0 URL request for ---> / Set timeout 0 URL request for ---> / What is the expected behavior? I expect single log and the middleware should run once. For a single request matching middleware should execute once not twice. Expected log Set timeout 0 URL request for ---> / What do you see instead? _No response_ Additional information _No response_
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: router.use middleware is called twice
Hello, and thank you for thia post. How long is the long running request? If is is 120 seconds, then Chrome will issue the request again and does not show this in the network console. You need to use a tool like Wireshark to see it issue the duplicate request.
Trust Score
1 verification
- 1
Hello, and thank you for thia post. How long is the long running request? If is
Hello, and thank you for thia post. How long is the long running request? If is is 120 seconds, then Chrome will issue the request again and does not show this in the network console. You need to use a tool like Wireshark to see it issue the duplicate request.
Validation
Resolved in expressjs/express GitHub issue #4736. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep