react / react/react-native

WebSocket.ping() on Android sends an empty binary frame instead of a protocol-level PING

オープン 初心者向け
#57,840 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Needs: Author Feedback Needs: Repro Platform: Android
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

WebSocket.ping() on Android sends an empty binary data frame (opcode 0x2) via OkHttp's
client.send(ByteString.EMPTY), instead of a real RFC 6455 PING control frame (opcode 0x9). On iOS,
ping() correctly sends a protocol-level ping via SocketRocket's sendPing:error:.

This breaks against WebSocket servers that reject binary frames (e.g. AWS API Gateway WebSocket APIs),
which close the connection with code 1003 UNSUPPORTED_DATA instead of responding with a pong.

The incorrect ping() that sends the empty frame is still present on the latest version (v0.86.2) of RN here: https://github.com/react/react-native/blob/v0.86.2/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.kt#L327

    try {
      client.send(ByteString.EMPTY)
    } catch (e: Exception) {
      notifyWebSocketFailed(id, e.message)
    }
Steps to reproduce
  1. Connect a WebSocket to a server that rejects binary frames (e.g. AWS API Gateway WS API).
  2. Call webSocket.ping() on Android.
  3. Observe the connection closes with 1003 UNSUPPORTED_DATA instead of receiving a pong.
React Native Version

0.86.2

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.5.2
  CPU: (12) arm64 Apple M4 Pro
  Memory: 106.66 MB / 24.00 GB
  Shell:
    version: "5.9"
    path: /opt/homebrew/bin/zsh
Binaries:
  Node:
    version: 23.10.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.2
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2025.05.19.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23726.103.2422.12816248
  Xcode:
    version: 26.2/17C52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /Users/inging/.jenv/shims/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
Logs from mitmproxy with a custom interceptor script:


<IP_REDACTED>:44604 -> WebSocket binary message -> <WSS_HOST_REDACTED>:443/
Error in WebSocket connection to <WSS_HOST_REDACTED>:443: WebSocket Error: UNSUPPORTED_DATA (reason: Binary is not supported)
MANDATORY Reproducer

https://gist.github.com/dekpient/4b611eb4efb58ecc1a881942f842a595

Screenshots and Videos

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.kt の327行目付近から始め、AndroidのパスとiOSの SocketRocket sendPing:error: を比較します。バイナリフレームを拒否するサーバーに対して必須の再現手順を使用し、AndroidがRFC 6455のPING(opcode 0x9)を送信し、1003 UNSUPPORTED_DATAで閉じなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, kotlin
領域
mobile, networking
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
78/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。