Hardcoded 5 second timeout for writing pong response can cause errors
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- go
- Ambito
- networking
Direzione di ricerca
Inizia con il flusso del ping in ingresso in read.go attorno all’handler opPing e con il percorso di scrittura del pong in write.go attorno ai contesti hardcoded di cinque secondi. Riproduci o analizza un mutex di scrittura bloccato e una connessione interrotta, quindi decidi come deve comportarsi il timeout ping/pong. Il lavoro è completato quando la connessione non fallisce più prematuramente nelle condizioni segnalate e il valore predefinito o la configurazione selezionati sono coperti dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
An inbound ping has a hardcoded 5 second deadline to handle the incoming message and send out a pong response. The general codepath for such a scenario is:
Conn.readLoop->h.opcode==opPing->handleControl(..., opPing)->writeControl(..., opPong)
The two 5 second context-based timeouts declared here:
- https://github.com/coder/websocket/blob/9f473adfa59519d1e0295cd7a988d965085b701a/read.go#L302
- https://github.com/coder/websocket/blob/9f473adfa59519d1e0295cd7a988d965085b701a/write.go#L277
These timeouts can cause the Websocket connection to close with an unrecoverable error. I can go into more detail about the two possible situations that can cause this condition if required, but just note that the network connection is extremely poor both in reliability and speed, and the connection is generally busy sending data (chunked enough to allow the incoming ping frames to be handled for the average network speed assuming no interruptions).
failed to get reader: failed to handle control frame opPing: failed to write control frame opPong: failed to acquire lock: context deadline exceeded
The problem mostly arises when the connection is briefly interrupted or the write mutex is otherwise busy underneath an in-flight inbound ping message. This 5 second timeout is not enough to be able to write the pong response.
Proposals:
- Allow this timeout value to be configurable - at the very least for ping/pong control frames.
- Increase this hardcoded timeout to 20 seconds by default - perhaps only for ping/pong frames?
This is generally more in line with other implementations I've found that have a default value - though most do not have a default timeout at all and rely on the user to implement ping handling in their own way.
- https://websockets.readthedocs.io/en/stable/reference/asyncio/client.html#websockets.asyncio.client.connect -
open_timeout=10, ping_interval=20, ping_timeout=20, close_timeout=10 - https://socket.io/docs/v4/server-options/#pingtimeout (granted this isn't a pure Websocket library)
Definitely open to other ideas, and I'm happy to get a PR up for this, but for now I've forked the repo to change this value.
- Lingua principale
- Go
- Stelle
- 5.5k
- Fork
- 377
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di coder/websocket
-
Must not wrap io.EOF Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
export wstest Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
Tutte le issue di coder/websocket
Issue simili
-
textual definition
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
geneontology/go-ontology#32653 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
needs design
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Priority/High ready-for-agent Severity/Major Type/Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100