Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open
#23 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
kotlin
Domain
api, backend

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

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.

Dominant language
Kotlin
Stars
402
Forks
60
Avg merge
4h 8m
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wangzhishou/OneBox

All issues in wangzhishou/OneBox

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.