`runBlocking(Dispatchers.IO)` inside NanoHTTPD request handlers risks thread starvation
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start in feature/file-transfer/src/main/java/com/wanbaohe/file_transfer/server/FileTransferServer.kt at lines 144 and 327, and inspect how NanoHTTPD dispatches these request handlers and how the Room queries are called. Compare the two proposed approaches, then verify concurrent chat-history and session requests do not starve the IO dispatcher or hang the server.
Written by the indexing model from the issue text.
Description
runBlocking(Dispatchers.IO) inside NanoHTTPD request handlers risks thread starvation
Severity: High
File: feature/file-transfer/src/main/java/com/wanbaohe/file_transfer/server/FileTransferServer.kt:144,327
Two methods use runBlocking to bridge coroutines to the synchronous NanoHTTPD handler:
fun getChatHistoryByChannel(channelId: String): List<ChatMessage> {
return runBlocking(Dispatchers.IO) {
chatDao.getMessagesByChannel(channelId).map { it.toChatMessage() }
}
}
fun listChatSessions(): List<ChatSession> {
return runBlocking(Dispatchers.IO) {
chatDao.listSessionSummaries().map { ... }
}
}
NanoHTTPD already dispatches each request on its own thread pool. Wrapping Room queries in runBlocking(Dispatchers.IO) creates a nested blocking call: the NanoHTTPD thread blocks waiting for a coroutine that itself blocks an IO-dispatcher thread. Under concurrent load (multiple browser tabs requesting history simultaneously), this can exhaust the Dispatchers.IO thread pool (default: 64 threads) and deadlock.
Why it matters
If several browser clients load the chat history page simultaneously, or if a Room migration is in progress, the blocking chain can starve the IO dispatcher and cause the entire server to hang. These methods should either use runBlocking without specifying Dispatchers.IO (since the caller is already off the main thread), or the server should be migrated to Ktor/cio which handles async natively.
- Dominant language
- Kotlin
- Stars
- 402
- Forks
- 60
- Avg merge
- 4h 8m
- Merged PRs (30d)
- 2
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from wangzhishou/OneBox
-
`androidCompileSdkExtension = "-"` silently becomes null, hiding the intended SDK extension levelOpengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wangzhishou/OneBox#20 · 1 comment ·
-
[aw] Detection RunsOpenagentic-workflows
Difficulty 1/5 Under an hour Newbie friendliness 10/100
wangzhishou/OneBox#30 · 3 comments ·
-
自定义AI添加失败Openbug
Difficulty 3/5 1-2 days Newbie friendliness 40/100
wangzhishou/OneBox#29 · 1 comment ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 70/100
wangzhishou/OneBox#22 · 1 comment ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 67/100
wangzhishou/OneBox#21 · 1 comment ·
All issues in wangzhishou/OneBox
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SimonHalvdansson/Harmonic-HN#363 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ionic-team/capacitor-file-transfer#83 · 1 comment ·
-
Meta request
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
keiyoushi/extensions-source#19500 ·
Maintainers usually reply within 1 day
-
go 🏃 testing 🧪
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
valkey-io/valkey-glide#7239 ·
Maintainers usually reply within 3 days