Hardcoded 5 second timeout for writing pong response can cause errors
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- go
- 領域
- networking
調査の方向性
read.go の opPing ハンドラー周辺にある受信 ping フローと、write.go のハードコードされた 5 秒のコンテキスト周辺にある pong 書き込みパスから始めます。書き込み mutex がブロックされた状態と接続が中断された状態を再現または検証し、そのうえで ping/pong タイムアウトがどのように動作すべきかを判断します。報告された条件で接続が早期に失敗しなくなり、選択したデフォルト値または設定がテストでカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Go
- スター
- 5.5k
- フォーク
- 377
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
coder/websocket のほかの issue
-
Must not wrap io.EOF オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
export wstest オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
coder/websocket の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
Bob Shell support オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
santhosh-tekuri/jsonschema#276 ·