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

Hardcoded 5 second timeout for writing pong response can cause errors

Aperta
#555 1 commento 4 reazioni 0 assegnatari Vedi su GitHub

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:

  1. https://github.com/coder/websocket/blob/9f473adfa59519d1e0295cd7a988d965085b701a/read.go#L302
  2. 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:

  1. Allow this timeout value to be configurable - at the very least for ping/pong control frames.
  2. 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.

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

  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 coder/websocket

Tutte le issue di coder/websocket

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.