WebSocket Connection Keeps Cloud Run Active—Need Auto-Disconnect Mechanism after specific timeout #4409
streamcfd
started this conversation in
Ideas / Feature Requests
Replies: 1 comment 4 replies
-
Hi @streamcfd, A client-side inactivity timer sounds reasonable: ui.add_body_html('''
<script>
let inactivityTimer;
function resetInactivityTimer() {
clearTimeout(inactivityTimer);
inactivityTimer = setTimeout(() => {
console.log('User has been inactive for 10 seconds');
window.socket.disconnect();
}, 10 * 1000);
}
document.addEventListener('DOMContentLoaded', () => {
resetInactivityTimer();
document.addEventListener('mousemove', resetInactivityTimer);
document.addEventListener('mousedown', resetInactivityTimer);
document.addEventListener('click', resetInactivityTimer);
document.addEventListener('keypress', resetInactivityTimer);
document.addEventListener('keydown', resetInactivityTimer);
document.addEventListener('touchstart', resetInactivityTimer);
document.addEventListener('touchmove', resetInactivityTimer);
document.addEventListener('scroll', resetInactivityTimer);
});
</script>
''') Is this what you're looking for? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
I am using Google Cloud Run for my app, which follows per-second billing as long as the app is in use, a client is connected, and the CPU is not idle.
I've noticed that if I leave a tab open in the browser, the CPU never goes idle because WebSocket messages are continuously sent.
Expected Behavior
Question
Is there any recommended approach to disconnect the WebSocket after a set period of inactivity on the client side? Or is there a way to require a manual page refresh for reconnection?
#2075 is similar, but I require complete disconnection after timeout so that CPU is idle.
Possible Solutions Considered
Any guidance or best practices would be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions