Search code examples
google-app-enginesocketschannel-api

Channel API /disconnect inbound service not called when tabs are closed in Chrome and FF


I create socket connection each time user logs into my application. This means if they open new tabs within same browser window multiple socket connections are established for each browser tabs. Problem occurs when I close these tabs; inconsistently /disconnect inbound service is called. This means for some connection /disconnect is not called and for some it is called. I can't reproduce this consistently (sometimes it called /disconnect sometimes it doesn't).

I am relying on /disconnect to clean up temporal objects created(stored in datastore) for a particular channel so I am left with all the OpenChannel objects for which /disconnect is never called.

This happens with Chrome and FireFox and never with IE. Am I using API correctly? Should there ever be one socket connection per browser window rather than tab? (If this is the case then if we store token in the cookie, do we re-establish connection with this token? Wouldn't this count as two connection per client id?

Thanks.


Solution

  • If you open more than two connections against a token created with the same client id, behavior becomes undefined. So if you're using, say, user.user_id() as the client id and the same user opens 3 tabs, you probably won't get the /disconnected callback for one of those tabs, even if you create new tokens for each of those tabs.