0

I have a node/express/socket.io app. When i run the app on android 4 and previous, it works just fine. However, with android 5.0+ and greater, every time my app loads and does its initial route (/), it sends the route function twice. The second time it executes, there is nothing in the request body, which is causing the app to error out.

app.post('/', someFunction);

Ive logged this function req.url and notice it is hitting someFunction twice for android 5.0+, but anything previous only hits it once and executes normally.

Does anyone have thoughts on to why this would be caused on new versions of android? and not others? Also to mention, this works just fine with iOS.

Dev123Dev
  • 194
  • 2
  • 13
  • Meandering thoughts: Are you using websockets.io or socket.io? Also what client are you using? It could be related to a "graceful fallback" if the client falls back on AJAX. It could also be a fast "transport upgrade" when using socket.io - socket.io starts with XHR and upgrades after testing the websocket connection, maybe on Android 5.0+ it's upgrading too fast for it's own good. – Myst Dec 02 '15 at 22:32
  • @Myst I am using socket.io, sorry not websockets.io. As far as client, Its a web view inside an android app. Has the problem on both the Simulator and live device hardware. Is that what you were referring to as CLIENT, or something else? – Dev123Dev Dec 02 '15 at 22:42
  • Thanks for clearing that up. Socket.io is both a client and a server framework, so I assume you're using the socket.io API on Android for your client side code... Can you log the transport layer of both requests (XHR vs. Websockets)? It could be related to socket.io's upgrade process, but I'm throwing darts in the dark. – Myst Dec 02 '15 at 22:50
  • @Myst lol, I wish i could tell you I know how to log the transport layer. – Dev123Dev Dec 02 '15 at 23:03
  • Wish I could help you with that... I never did Android with socket.io (I'm not a complete fan of the framework and I prefer directly using Websockets). – Myst Dec 03 '15 at 00:01
  • @Myst See my answer below, i would love to know your thoughts on why this is the way it is – Dev123Dev Dec 03 '15 at 16:52

1 Answers1

0

The problem was not related to sockets.io. It had to do with how the newer android OS web view handles some JS. In my EJS templates associated with that route, I have a

    window.location.reload();

This works great with iOS and older android OS's, but the new versions didn't like it. I was able to switch to:

window.location.href = window.location.href;

And this seems to work just dandy.

Dev123Dev
  • 194
  • 2
  • 13
  • I'm happy you found a solution, though I must admit this is a surprise. The only difference I can think of has to do with caching ([see here](http://stackoverflow.com/questions/2405117/difference-between-window-location-href-window-location-href-and-window-location))... maybe some javascript is relying on content that didn't finish loading (is something running before the `onload` event?)... could be glitch (similar to [this](https://code.google.com/p/chromium/issues/detail?id=327728))... funky :) – Myst Dec 03 '15 at 17:55
  • @Myst let me ask you another question, you might know the answer too. With same app, for older versions of Android, i get a constant page loading wheel, and it never stops. But for newer versions, it works just fine. Anything stick out to you? – Dev123Dev Dec 03 '15 at 19:31
  • I have no idea... I think I would need to read more of the code to track down the issue. Either way, good luck! – Myst Dec 03 '15 at 19:52