Skip to content

Nested iso collections cannot be created from the state runner thread (causes deadlock) #72

@alusch

Description

@alusch

We have a bit of fairly complicated logic in our project that uses an IsoMutableMap whose value is another IsoMutableMap, something like

val nested = IsoMutableMap<Int, IsoMutableMap<Int, Int>>()

As part of a recent change, we ended up with some code that boils down to

nested.access {
    it[0] = IsoMutableMap()
}

and were surprised to find that this causes a deadlock:

  1. IsoMutableMap constructor calls createState
  2. That function isn't aware of the StateHolder so it just directly calls runner.stateRun, not realizing we're already on the thread it wants to run on
  3. Work gets enqueued to run on the current thread later
  4. Current thread blocks on that future work - deadlock

Not sure if there's a clean way that the threading information could be conveyed here to do the right thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions