Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#270 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

@mpf82 ci sta già lavorando.

Dal 7/5/2025.

  • #298 di @mpf82 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
networking

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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())
Lingua principale
Python
Stelle
1.1k
Fork
284
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Lawouach/WebSocket-for-Python

Tutte le issue di Lawouach/WebSocket-for-Python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.