Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Messages sent are received "one behind" when using WSS.

Abierto
#270 2 comentarios 1 reacción 0 asignados Ver en GitHub

@mpf82 ya está trabajando en esto.

Desde el 7/5/2025.

  • #298 de @mpf82 — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
python
Área
networking

Línea de trabajo

Reproduce the behavior using test.py and test.html with both ws:// and wss://, comparing the logged received_message output and browser responses. Trace the WSS receive path first and identify why messages lag by one; done means consecutive client messages are received and echoed immediately in WSS mode as they are in WS mode.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ws4py==0.5.1
CherryPy==18.6.0
Python 3.9.5 / Mac OS 11.4 (M1)

Messages are received as expected when I use WS. If I switch to WSS, messages sent by the client/browser are not received by the server until after a subsequent message is sent by the client (which in turn is also delayed). Once the second message is sent, the first message is received.

I note issue https://github.com/Lawouach/WebSocket-for-Python/issues/191 which appears to be similar.

Output from attached test client and server:

WS mode
Chrome console:

on open
sent: one
sent: two
sent: three
Message received:one back
Message received:two back
Message received:three back

Python output:

2021-07-04 19:46:11,986:INFO: Using select as epoll is not available
2021-07-04 19:46:11,986:INFO: [04/Jul/2021:19:46:11] ENGINE Listening for SIGTERM.
2021-07-04 19:46:11,986:INFO: [04/Jul/2021:19:46:11] ENGINE Listening for SIGHUP.
2021-07-04 19:46:11,986:INFO: [04/Jul/2021:19:46:11] ENGINE Listening for SIGUSR1.
2021-07-04 19:46:11,986:INFO: [04/Jul/2021:19:46:11] ENGINE Bus STARTING
2021-07-04 19:46:11,986:INFO: [04/Jul/2021:19:46:11] ENGINE Starting WebSocket processing
2021-07-04 19:46:11,986:INFO: [04/Jul/2021:19:46:11] ENGINE Started monitor thread 'Autoreloader'.
2021-07-04 19:46:12,089:INFO: [04/Jul/2021:19:46:12] ENGINE Serving on http://127.0.0.1:9000
2021-07-04 19:46:12,090:INFO: [04/Jul/2021:19:46:12] ENGINE Bus STARTED
2021-07-04 19:46:24,695:INFO: in /test
2021-07-04 19:46:24,696:INFO: 127.0.0.1 - - [04/Jul/2021:19:46:24] "GET /test HTTP/1.1" 101 - "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-07-04 19:46:24,696:INFO: Managing websocket [Local => 127.0.0.1:9000 | Remote => 127.0.0.1:61575]
2021-07-04 19:46:24,935:INFO: received_message:one
2021-07-04 19:46:24,936:INFO: received_message:two
2021-07-04 19:46:24,937:INFO: received_message:three

WSS mode
Chrome console:

on open
sent: one
sent: two
sent: three
Message received:one back
Message received:two back

Python output:

2021-07-04 19:49:39,967:INFO: Using select as epoll is not available
2021-07-04 19:49:39,967:INFO: [04/Jul/2021:19:49:39] ENGINE Listening for SIGTERM.
2021-07-04 19:49:39,967:INFO: [04/Jul/2021:19:49:39] ENGINE Listening for SIGHUP.
2021-07-04 19:49:39,967:INFO: [04/Jul/2021:19:49:39] ENGINE Listening for SIGUSR1.
2021-07-04 19:49:39,967:INFO: [04/Jul/2021:19:49:39] ENGINE Bus STARTING
2021-07-04 19:49:39,967:INFO: [04/Jul/2021:19:49:39] ENGINE Starting WebSocket processing
2021-07-04 19:49:39,967:INFO: [04/Jul/2021:19:49:39] ENGINE Started monitor thread 'Autoreloader'.
2021-07-04 19:49:40,073:INFO: [04/Jul/2021:19:49:40] ENGINE Serving on https://127.0.0.1:9000
2021-07-04 19:49:40,073:INFO: [04/Jul/2021:19:49:40] ENGINE Bus STARTED
2021-07-04 19:49:56,428:INFO: in /test
2021-07-04 19:49:56,429:INFO: 127.0.0.1 - - [04/Jul/2021:19:49:56] "GET /test HTTP/1.1" 101 - "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
2021-07-04 19:49:56,430:INFO: Managing websocket [Local => 127.0.0.1:9000 | Remote => 127.0.0.1:62492]
2021-07-04 19:49:56,641:INFO: received_message:one
2021-07-04 19:49:56,642:INFO: received_message:two

test.html

<!DOCTYPE HTML>

<html>

<head>
    <script type="text/javascript">
        function webSocketTest() {
            if ("WebSocket" in window) {
                var socket = new WebSocket("wss://local.example.com:9000/test");
                //var socket = new WebSocket("ws://local.example.com:9000/test");

                function send(text) {
                    socket.send(text)
                    console.log(`sent: ${text}`)
                }

                socket.onopen = function () {
                    console.log("on open")
                    send("one");
                    send("two");
                    send("three");
                };

                socket.onmessage = function (event) {
                    var received = event.data;
                    console.log(`Message received: ${received}`);
                };
            }
            else {
                console.log("No WebSocket support");
            }
        }
    </script>
</head>

<body>
    <div>
        <input id="run" type="button" value="Upgrade" onclick="webSocketTest();" />
    </div>
</body>

</html>

test.py

#!/usr/bin/env python3

import sys
import logging

import cherrypy
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from ws4py.websocket import WebSocket


class TestWebSocket(WebSocket):
    def received_message(self, message):
        message = message.data.decode('utf8')
        logging.info("received_message:%s", message)
        self.send(f"{message} back")


class Root:
    @cherrypy.expose
    def test(self):
        logging.info("in /test")


def main():
    logging.basicConfig(level=logging.DEBUG, format="%(asctime)s:%(levelname)s: %(message)s")

    config = {
        "global": {
            "server.ssl_module": "builtin",
            "server.ssl_certificate": "/etc/ssl/certs/STAR_example_com.chain.pem",
            "server.ssl_private_key": "/etc/ssl/private/STAR_example_com.key",
            "server.socket_port": 9000,
            "log.screen": False,
        },
        "/test": {
            "tools.websocket.on": True,
            "tools.websocket.handler_cls": TestWebSocket,
        }
    }

    WebSocketPlugin(cherrypy.engine).subscribe()
    cherrypy.tools.websocket = WebSocketTool()
    cherrypy.quickstart(Root(), "/", config=config)


if __name__ == "__main__":
    sys.exit(main())
Lenguaje dominante
Python
Estrellas
1.1k
Forks
284
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Lawouach/WebSocket-for-Python

Todos los issues de Lawouach/WebSocket-for-Python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.