Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phoenix channel's socket keeps getting closed in distributed cluster environment

I followed this series of articles to create a deployment at Google Cloud. Everything is working as expected, except phoenix channels.

No errors on the backend side. On Javascript frontend I am getting first channel ERROR and then the socket CLOSES on frontend while using channels. And this keeps repeating endlessly in an interval of 10–20 secs.

CHANNEL ERROR!
SOCKET CLOSE!
CHANNEL ERROR!
SOCKET CLOSE!

From this code:

socket.connect()
socket.onError( e => console.log("SOCKET ERROR", e) )
socket.onClose( e => console.log("SOCKET CLOSE", e))
channel = socket.channel("note:" + noteId, {})
channel.onError( e => console.log("CHANNEL ERROR!", e) )
channel.onClose( e => console.log("CHANNEL CLOSED!", e) )

I need help to debug this and figure out where this problem is originating from. Please let me know if any piece of code is needed and I will update the question with that code. Its been a week now. :(

Thanks a lot!

(No problem when run locally)

UPDATE: The only difference I am seeing is that on local server, phoenix.js is continuously sending heartbeat but this is not happening on server.

UPDATE:

---- my-ingress.yaml ----
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    # ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.global-static-ip-name: my-ingress-ip
    kubernetes.io/tls-acme: "true"
spec:
  rules:
  - host: apiv2.example.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: my-service-nodeport
          servicePort: 80
      - path: /.well-known/acme-challenge
        backend:
          serviceName: kube-lego-gce
          servicePort: 8080
  tls:
  - secretName: my-secret-tls-7
    hosts:
    - apiv2.example.com

This is ingress file I am using and also using kube-lego with it.

UPDATE: I implemented this code (I checked frames in dev tools, they were being sent). But still... its giving SOCKER ERROR. May be issue is not with sending hearbeats.

const HEARTBEAT_INTERVAL_MS = 5000
socket.onOpen(() => {
      clearInterval(this.heartbeatTimer);
      this.heartbeatTimer = setInterval(() => { 
        return socket.push({ 
          topic: "phoenix", 
          event: "heartbeat", 
          payload: {}, 
          ref: socket.makeRef(), 
        }); 
      }, 
        HEARTBEAT_INTERVAL_MS
      );
    })
like image 617
abhinav Avatar asked Oct 27 '17 09:10

abhinav


People also ask

What is Phoenix notification channel?

Phoenix channels run over WebSocket protocol and require some service messages for the server part to distinguish between different topics. This plug-in uses same JavaScript implementation which is bundled with Phoenix and provides nice UI to make it easier to use.

What is Phoenix socket?

Phoenix. Socket is used as a module for establishing and maintaining the socket state via the Phoenix. Socket struct. Once connected to a socket, incoming and outgoing events are routed to channels. The incoming client data is routed to channels via transports.

What are Phoenix channels?

Channels are an exciting part of Phoenix that enable soft real-time communication with and between millions of connected clients. Some possible use cases include: Chat rooms and APIs for messaging apps.


1 Answers

You may need to increase the response timeout for your backend service on GCP.

By default, the timeout was set at 30sec and was causing the same problem for me.

like image 139
abagshaw Avatar answered Sep 29 '22 15:09

abagshaw