Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`runBlocking(Dispatchers.IO)` inside NanoHTTPD request handlers risks thread starvation

Aperta
#23 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
kotlin
Ambito
api, backend

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

bug

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wangzhishou/OneBox

Tutte le issue di wangzhishou/OneBox

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.