`runBlocking(Dispatchers.IO)` inside NanoHTTPD request handlers risks thread starvation
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Kotlin
- Stelle
- 402
- Fork
- 60
- Merge medio
- 4h 8m
- PR unite (30g)
- 2
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di wangzhishou/OneBox
-
`androidCompileSdkExtension = "-"` silently becomes null, hiding the intended SDK extension levelApertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wangzhishou/OneBox#20 · 1 commento ·
-
[aw] Detection RunsApertaagentic-workflows
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 10/100
wangzhishou/OneBox#30 · 3 commenti ·
-
自定义AI添加失败Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 40/100
wangzhishou/OneBox#29 · 1 commento ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
wangzhishou/OneBox#22 · 1 commento ·
-
Resource exclusion pattern `org/` silently strips resources from all `org.*` library packagesApertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
wangzhishou/OneBox#21 · 1 commento ·
Tutte le issue di wangzhishou/OneBox
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
modelcontextprotocol/kotlin-sdk#1088 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
openwallet-foundation/multipaz#2040 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ohs-foundation/kotlin-fhir#143 ·
-
Feature request
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
keiyoushi/extensions-source#19546 ·
I maintainer di solito rispondono entro 1 giorno
-
bug triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
d4rken-org/sdmaid-se#2820 ·
I maintainer di solito rispondono entro 1 giorno