Utilizing various comet techniques like long polling and forever frame, along with iframes for cross subdomain activities, has presented a challenge during implementation. When a user refreshes the page or navigates to another page, a new request is made while the previous comet connection remains open. Despite my server (tornado) never receiving a connection close signal and no TCP fin packet being detected through wireshark, the sockets are eventually closed upon closing the browser.
These lingering open connections not only consume unnecessary memory on the server side but also create issues when the server tries to send messages to these open sockets resulting in error messages displayed by IE such as "Can't execute code from a freed script". It seems like IE is attempting to execute code on a window that was already navigated away from. How have others addressed this issue? Is using onbeforeunload to manage connection closure a viable solution?