Skip to content

ResultChunkAssembler is not thread-safe and does not say so #67

@nficano

Description

@nficano

ResultChunkAssembler holds chunk state in a plain mutableMapOf() at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:13 and exposes accept as a non-suspend function at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:16. The class KDoc at lib/src/main/kotlin/dev/arcp/client/ResultChunkAssembler.kt:9 does not mention thread safety, and the README example at README.md:171 constructs one assembler and calls accept from a flow collect { … } block where it is easy to imagine sharing the instance across coroutines. Two coroutines calling accept for the same resultId concurrently can corrupt the buffers map.

Fix prompt: Add a one-line KDoc stating "Not thread-safe — use one assembler per result stream and call accept from a single coroutine." Optionally back the map with a Mutex and make accept suspend if the use case actually warrants concurrent assembly. Add a small unit test asserting the single-coroutine contract — or, if the synchronized version is implemented, a stress test that hammers accept from multiple coroutines and verifies the assembled output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationseverity:lowLow severity issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions