Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websockets not working over TLS (wss) #854

Closed
ianhalpern opened this issue Sep 16, 2019 · 1 comment
Closed

Websockets not working over TLS (wss) #854

ianhalpern opened this issue Sep 16, 2019 · 1 comment

Comments

@ianhalpern
Copy link

ianhalpern commented Sep 16, 2019

Hi,

I've been trying to debug the issue with a simple socket.io app on GKE. Websockets/Socket.io works fine over HTTP (ws://) but when switching to HTTPS (wss://) the client does receive a valid response with a Sec-WebSocket-Accept header but within a second or two after the handshake the connection gets closed and no messages are relayed. Below is the configuration. I tried to keep it plain and simple.

Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: flask-ws-ingress
spec:
  rules:
  - host: my-domain.com
    http:
      paths:
      - path: /*
        backend:
          serviceName: flask-ws-app-svc
          servicePort: 80
  tls:
    - hosts:
      - my-domain.com
      secretName: domain-tls-cert

Service:

apiVersion: v1
kind: Service
metadata:
  name: flask-ws-app-svc
  labels:
    name: flask-ws-app
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
    name: http
  type: ClusterIP
  selector:
    name: flask-ws-app

Deployment

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: flask-ws-app
  labels:
    name: flask-ws-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: flask-ws-app
  template:
    metadata:
      name: flask-ws-app
      labels:
        name: flask-ws-app
    spec:
      containers:
        - name: flask-ws-app
          image: gcr.io/project/flask-ws-app:v3
          ports:
            - containerPort: 8080

Flask App

from flask import Flask, send_from_directory
from flask_socketio import SocketIO, send
import config

app = Flask(__name__)
app.config.from_object('config')
app.config["SECRET_KEY"] = "secret!"
socketio = SocketIO(app)

@socketio.on('message')
def handle_message(message):
    send('echo from server: '+message)

if __name__ == "__main__":
    socketio.run(app, port=config.PORT, debug=True)
@nisharma2023
Copy link

hi @ianhalpern how did you fix this issue? I am running into same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants