Skip to content

fix(android): prevent NPE in WebSocketClient.sendFrame() after disconnect#4554

Open
hobostay wants to merge 1094 commits intoTencent:mainfrom
hobostay:fix/websocket-null-safety
Open

fix(android): prevent NPE in WebSocketClient.sendFrame() after disconnect#4554
hobostay wants to merge 1094 commits intoTencent:mainfrom
hobostay:fix/websocket-null-safety

Conversation

@hobostay
Copy link
Copy Markdown

Summary

  • Fix NullPointerException in WebSocketClient.sendFrame() that occurs when sending data after disconnect() has been called
  • disconnect() sets mSocket = null on the handler thread, but sendFrame() is also posted to the same handler thread and accesses mSocket.getOutputStream() without a null check
  • Added a null guard before accessing mSocket to gracefully skip the send when the socket has been closed

How the bug occurs

  1. WebSocket connection is established
  2. disconnect() is called, which posts a Runnable to mHandler that sets mSocket = null
  3. Meanwhile, sendFrame() is also posted to mHandler (from send() or pong response)
  4. If sendFrame runs after disconnect, mSocket is null → NullPointerException

Test plan

  • Connect a WebSocket, send messages, then disconnect and verify no NPE
  • Verify that send operations after disconnect are silently skipped (no crash)
  • Verify normal WebSocket communication is unaffected

🤖 Generated with Claude Code

ozonelmy and others added 30 commits February 20, 2023 07:53
Tencent#2849)

refactor(andr): prod remotedebug feature optimized

fix(andr): prod remotedebug createDebugUrl fixed

fix(andr): prod remotedebug optimize

(cherry picked from commit 25cce417d76c8cc729e0be1c6909076e7cad79db)

fix(andr): vue add tagName for debug in prod

fix(andr): change variable mProdRemoteDebugMode to mPureDebugMode

refactor(andr): add enum DebugMode to manage different mode

fix(andr): optimize debugMode code

fix(andr): logical judgment instead of instance variables to optimize

fix(andr): fix No correct copyright header;

fix(hippy-vue): fix unit test tagName fail
* feat(ios): add and correct some entries in performance logger

* docs(performance): update performance guide

* feat(android): record separate event for `TimeMonitor`

* feat(docs): add android time monitor docs

* feat(docs): add startup performance guide

* feat(ios): add performanceLogger module

* fix(android,js): update performance api

* refactor(android): load time report

* fix(android): code style problems

* refactor(android): change monitor api

* refactor(ios): update performance module with turbo imp

* chore(android): add copyright header

* refactor(android,ios): remove instanceId implement

* feat(docs): add minimum support version

* refactor(android): rename nativeCallback method

* refactor(android): use single payload param in nativeCallback method

* feat(bridge): revert style changed

---------

Co-authored-by: iPel <pel20121221@gmail.com>
Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com>
…ng (Tencent#2521)

* feat(ios): rich text images support vertical alignment setting

* feat(ios): add rich text's vertical align offset support

* feat(ios): margin support for nested component in richText

* feat(android): add `verticalAlign` for `Image` in rich text

* fix(android): backgroundColor not working in nested text

* feat(android): add properties for `Image` in rich text

`tintColor`, `backgroundColor`, `margin` and `padding`

* feat(ios): text in rich text support verticalAlign setting

* feat(android): verticalAlign for textnode

* feat(android): add backgroundColor in legacy mode

* fix(android): baseline align offset wrong

* feat(ios): support nested text verticalAlign style setting

* fix(android): verticalAlign for boringLayout

* chore(docs): add verticalAlign docs

* chore(ios): make verticalAlign default value baseline

* feat(vue): update text demo

* chore(ios): add verticalAlign and update demo

* chore(docs): update verticalAlign minimum supported version

---------

Co-authored-by: iPel <pel20121221@gmail.com>
Co-authored-by: luomy <ozonelmy@163.com>
Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com>
* fix(android): textInput may throw IllegalStateException

* fix(android): textInput may throw IllegalStateException

---------

Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com>
* fix(android): fix unit test case

* fix(android): add license header
feat(docs): add en docs for UserLocal debug mode;
zealotchen0 and others added 13 commits October 29, 2024 17:44
* feat(react): add animation stop

* feat(web): fix image local path

* feat(web): remove unused code
* feat(react): add animation stop

* feat(chore): romove security check

* chore(react): remove unused code
…nect

The sendFrame() method could throw a NullPointerException when called
after disconnect(), since disconnect() sets mSocket to null on the
handler thread while sendFrame() is also posted to the same handler.
Added a null check before accessing mSocket.getOutputStream().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@hippy-service
Copy link
Copy Markdown

hippy-service Bot commented Apr 22, 2026

Hi, @hobostay. Thanks for your PR! 👏

🏷️ You can leave a comment in this PR with #help tag when you need help (e.g. some status checks run failed due to internal issue), admin team members will help asap.

@tencent-adm
Copy link
Copy Markdown
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 5 committers have signed the CLA.

✅ wwwcg
✅ zealotchen0
❌ 1780243524
❌ etkmao
❌ Test User


Test User seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.