Skip to content

fix: prevent NullPointerException in write() on Android due to TOCTOU race condition with destroy() (#233) - #234

Merged
Rapsssito merged 5 commits into
Rapsssito:masterfrom
maoweipeng:master
Jul 26, 2026
Merged

Rapsssito merged 5 commits into
Rapsssito:masterfrom
maoweipeng:master

Conversation

@maoweipeng

Copy link
Copy Markdown
Contributor

No description provided.

@Rapsssito
Rapsssito merged commit f85d07d into Rapsssito:master Jul 26, 2026
1 check passed
github-actions Bot pushed a commit that referenced this pull request Jul 26, 2026
## [6.4.2](v6.4.1...v6.4.2) (2026-07-26)

### Bug Fixes

* **iOS:** emit error when onConnect hosts are nil ([#235](#235)) ([3d99c5f](3d99c5f))
* pass through all listen options to native, including tls ([#236](#236)) ([55bf524](55bf524))
* prevent NullPointerException in write() on Android due to TOCTOU race condition with destroy() ([#233](#233)) ([#234](#234)) ([f85d07d](f85d07d))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

bardbess added a commit to bardbess/react-native-tcp-socket that referenced this pull request Sep 8, 2026
…o#203)

TcpSocketClient's constructor creates two Executors.newSingleThreadExecutor() and destroy() shut down neither. A single-thread executor keeps its core thread alive indefinitely, so every connection ever opened left two live threads and their stacks behind - the unbounded thread and memory growth reported in Rapsssito#203, where a server that closes each socket immediately still grows until the OS kills the process.

shutdown() rather than shutdownNow(), so the receiver task ends on its own once the socket is closed and an already-accepted write still reaches the wire, and in a `finally` so it happens whether or not the close threw.

write() now catches the RejectedExecutionException a shut-down executor throws and reports the same "Attempted to write to closed socket" it already reports for a null socket, rather than letting it reach the bridge uncaught. Caught rather than guarded with isShutdown(), which would reintroduce the check-then-act race fixed in Rapsssito#233/Rapsssito#234.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants