Close() aborts the closing handshake when an in-flight Ping arrives after Close is sent
Les mainteneurs répondent en général sous 3 jours
Personne n'a encore pris cette issue.
- #595 par @Mohith26 — fermée sans fusion
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 72/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- go
- Domaine
- networking
Piste de recherche
Start by reading writeFrame, handleControl, and waitCloseHandshake, then run the raw-socket reproduction described in the issue to confirm the missing Pong and unread peer Close. Check the existing close and Ping tests for nearby coverage. Done means a Ping received after sending Close gets the required Pong, the peer's Close is consumed, and the regression is covered by a test.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Description
Conn.Close does not complete the RFC 6455 closing handshake when a Ping that was already on the wire arrives after this endpoint has sent Close.
What happens:
writeClosesetscloseSentErr.waitCloseHandshake→readLoop→handleControlseesopPingand callswriteControl(opPong, …).writeFramereturnsnet.ErrClosedbecausecloseSentErr != nil(every opcode is refused after Close).- That error aborts the drain before the peer's Close is read.
Close's defer turnserrors.Is(err, net.ErrClosed)intonil, so the caller sees success.- No Pong is written; the peer's Close is never consumed; TCP is closed anyway.
Data frames and a peer Close alone in the same state are fine (waitCloseHandshake discards data and returns on Close). Only Ping breaks the drain.
Spec
RFC 6455 §5.5.2:
Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in response, unless it already received a Close frame.
At this point Close has been sent, not received, so a Pong is required. §5.5.1 forbids further data frames after Close; Pong is a control frame. §7.1.2 expects the endpoint to finish sending and receiving Close before tearing down TCP.
Reproduction
Raw-socket peer that lets the library send Close first, then writes Ping+Close without having read that Close (simulates frames written before the peer saw Close):
// library side
c, _ := websocket.Accept(w, r, &websocket.AcceptOptions{
OnPingReceived: func(ctx context.Context, payload []byte) bool { return true },
})
_ = c.Write(ctx, websocket.MessageText, []byte("ready"))
time.Sleep(100 * time.Millisecond)
err := c.Close(websocket.StatusNormalClosure, "server-close")
// err == nil even when the peer's Close was never read
# peer: after reading "ready", wait until library Close is on the wire, then
# write Ping + Close without reading
sock.send(ping_frame)
sock.send(close_frame(1000))
# observe: library Close arrives, TCP closes, **no Pong**
Observed on master @ 5d0eacc and v1.8.15: Close() returns nil, OnPingReceived fires, no Pong on the wire, peer Close unread.
Controls: same harness with only Data+Close, or only Close, completes cleanly.
Suggested fix
In writeFrame, keep rejecting writes after Close except for opPong:
if closeSentErr != nil {
if opcode != opPong {
return 0, net.ErrClosed
}
}
That restores the §5.5.2 Pong and lets waitCloseHandshake continue to the peer Close. Verified locally against the repro above; happy to open a PR.
Related
- #298 / #394 — outbound Ping racing
Closeon the write lock / proposal to discard inbound Ping after Close. Closed via28c6709(TestConcurrentClosePingwrite-timeout reset). That did not cover thecloseSentErr→ abort →net.ErrClosedswallow path here. - #555 — 5s pong write timeout under contention (different).
- #448 / #476 — other close/write races (fixed).
- Langage dominant
- Go
- Étoiles
- 5.6k
- Forks
- 394
- Merge moyen
- 4 j 12 h
- PR mergées (30 j)
- 11
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de coder/websocket
-
Must not wrap io.EOFPeut-être pris @Yanhu007 l’a pris il y a 223 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
coder/websocket#561 · 1 réaction ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 3 jours
-
export wstestOuverteenhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
coder/websocket#340 · 5 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 3 jours
-
ci: Daily tests fail?Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 22/100
coder/websocket#598 · 3 commentaires ·
Les mainteneurs répondent en général sous 3 jours
-
Read returns a truncated fragmented message as complete when the connection closes mid-messagePeut-être pris @Grivn l’a pris il y a 38 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de coder/websocket
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
uselagoon/lagoon-cli#501 · 1 réaction ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 62/100
slavakurilyak/awesome-ai-agents#1026 ·
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Tarektouati/made#197 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100