How to Fix Delayed User Activity Times in Node.js WebSocket Behind Apache?

0
15
Asked By Sparky12345 On

I've set up a Node.js WebSocket server on port 6060, and it's running behind an Apache web server. When someone accesses my app at www.mydomain.com/app/, a unique ID is assigned to them, along with tracking their username, entry time, and eventually, their last active time.

The problem I'm facing is that when a user closes their browser tab, Apache receives the FIN signal right away, but it keeps the connection to Node.js active for an additional 30 to 40 seconds. Consequently, the 'last active time' gets logged with a significant delay—around 35 seconds after the user has actually exited.

I've tried enabling flushpackets, adjusting timeout values, and tweaking other settings in Apache, but the delay remains. It seems that Apache holds the connection until its internal I/O timeout hits, which slows down the release of the Node backend.

Just to clarify, the code runs perfectly fine on my local environment, so the code itself isn't the issue!

4 Answers

Answered By WebDevWizard On

Do you really need that level of accuracy for user activity time? You could just add a little delay in your code to account for the timeout before closing the connection. This way, you avoid digging into complicated Apache settings that might change depending on your proxy technology. Just make sure any changes are generic and configurable!

Answered By DevNinja88 On

Can you share your local Apache configuration and version? It might help to compare it to what you're using in production to spot any differences.

Answered By ServerSmith On

Have you thought about adding disablereuse=on to your Apache proxy settings? It could help with your connection handling.

Answered By NodeGuru89 On

Just a heads up, saying it works on your local machine doesn't really help here. It's a classic case of 'works on my machine'! A FIN packet is just the client's way of saying it's ready to close the TCP connection, but the server still has to handle some stuff before it sends back the final FIN, which includes an ACK from the client side to actually close it.

You might want to check how long it takes for your server to send that final FIN after receiving the client's FIN. Also, don't forget to consider any possible network latency or connection issues!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.