Repository navigation
fix(file-transfer): expire authenticated sessions and drop nested runBlocking - #33
Merged
wangzhishou merged 2 commits intoOct 7, 2026
Conversation
…Blocking Authenticated sessions were kept in a plain set that was never pruned, and changing the transfer password left every previously issued session cookie valid. Track sessions as sessionId -> last seen timestamp with a 30 minute sliding expiry, a cap of 64 entries, and clear the map when the password changes. getChatHistoryByChannel() and listChatSessions() also bridged NanoHTTPD worker threads through runBlocking(Dispatchers.IO); both callers are already off the main thread, so the extra hop is dropped.
pruneExpiredSessions() ran before the requesting session's timestamp was refreshed, so at the session cap the entry chosen for eviction could be the one being validated and that browser was sent back to the password prompt. Refresh (or insert, in handleAuth) first and prune after: the freshly touched entry has the newest timestamp, so the cap cannot pick it, and the map is no longer one entry over the cap between an auth and the next request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
FileTransferServerkept authenticated sessions in amutableSetOf<String>()that was only ever written to. Three changes infeature/file-transfer:sessionId -> lastSeenAtin aConcurrentHashMapwith a 30 minute sliding expiry: every authenticated request refreshes the timestamp, and expired entries are pruned lazily on the request path, so no background job is needed.MAX_SESSIONS = 64caps the map and evicts the least recently seen entries, so browser reconnect churn cannot grow it without bound. The entry being validated is refreshed before pruning runs, so the cap can never pick the session that just authenticated and send that browser back to the password prompt.updateConfig()clears the map when the password actually changes, so sessions issued under the previous password stop being accepted.getChatHistoryByChannel()andlistChatSessions()no longer wrap their Room queries inrunBlocking(Dispatchers.IO). Both are called from NanoHTTPD worker threads, which are already off the main thread, so the second hop only borrowed an IO thread.How it was verified
./gradlew :feature:file-transfer:compileFossUniversalDebugKotlin— BUILD SUCCESSFUL./gradlew :app:assembleFossUniversalDebug— BUILD SUCCESSFUL./gradlew :feature:file-transfer:detekt— 193 findings, identical to the count onmain; the change adds none.isAuthenticated(),refreshSession()andpruneExpiredSessions()all stay inside the defaultReturnCountand complexity limits.Not verified on a device: the expiry itself and the browser-side logout after a password change, both of which need a running file transfer service and two clients.