0

I deployed a Socket.io based app in GKE. I already use Redis adapter to handle multiple pods. Cookie affinity already set in Ingress setting.

I use dynamic namespace. I ONLY USE 1 POD on GKE. When I scaled from 1 pod to 0 pod, then to 1 pod again, did it repeatedly, sometimes socket.io works, sometimes its does not works. When it does not works, here is the VERY STRANGE behavior I observed:

  • On connection event on server side not fired, event though the socket already connected. I know socket already connected because I printed all of them.

I doubted Redis adapter? Anyone has seen this before?

Thanks!

  • Hi, could you please add the [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your issue for reproduction purposes? Also, could you please tell what exactly you mean by the: *`socket.io` sometimes works, sometimes it does not works*? – Dawid Kruk May 19 '21 at 14:02
  • Thanks, I found the issue. It because of the dynamic namespace. The problem is, when you use `io.of(nsp)`, if the nsp is not created yet, it will created with an `undefine` on connect handler. Therefore, our dynamic namspace on connect handler were not set – Vuong Nguyen May 20 '21 at 07:53
  • I'm glad that you've found the solution to your issue. As you were the founder of it, please consider creating an answer with an explanation for better visibility to the community as well as to indicate that you've managed to solve it. – Dawid Kruk May 20 '21 at 12:37

1 Answers1

1

Posting this answer as a community wiki to highlight the fact that the issue was resolved.

Feel free to edit and expand.


As posted in the comments:

Thanks, I found the issue. Its because of the dynamic namespace. The problem is, when you use io.of(nsp), if the nsp is not created yet, it will be created with the undefine on the connect handler. Therefore, our dynamic namespace on connect handler was not set.


Additional resources:

Dawid Kruk
  • 8,982
  • 2
  • 22
  • 45