Comet issue with abandoned open connections
Asked Answered
E

1

4

I am using some comet techniques including long polling and forever frame. I am using iframes for cross subdomain stuff. The one issue that I ran into while implementing these techniques is when a user refreshes a page or navigates to another page causing a new request, the comet connection is kept open from the old page. My server (tornado) never receives a connection close and from my limited wireshark abilities I don't see any TCP fin packet sent. However, when I close the the browser, the sockets are closed at that point.

These abandoned open connections are just using up memory on the server side for no good reason. Also it causes problems when the server sends some message to the open socket and IE then correctly displays an error message: "Can't execute code from a freed script". So IE is trying to execute code on the old window which was navigated away from. How are other people handling this issue? Should I use onbeforeunload to somehow close the connection?

Easygoing answered 18/1, 2011 at 1:13 Comment(0)
C
1

You could restart an open connection every now and then from the client side and if the request did not come in to the server in the specified time-frame you can safely close the old connection.

Carpio answered 18/1, 2011 at 3:55 Comment(2)
Well that doesn't really solve the problem. What if a user refreshes the page and the server sends a message to this abandoned connection before the timeout occurs?Easygoing
Page refresh should start a new connection. There can only be one active connection per user/window at a time, so you could just use the most recent connection. Or send your messages to all open connections.Carpio

© 2022 - 2024 — McMap. All rights reserved.