Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alusch opened this issue Nov 12, 2021 · 2 comments

Comments

@alusch
Copy link
Contributor

alusch commented Nov 12, 2021

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.

@russhwolf
Copy link
Contributor

You might be able to work around by manually passing separate StateRunners

@kpgalligan
Copy link
Contributor

I'd need to think about this. We have some internal constructors that let you fork off state. Not on IsoMutableMap, though. You may be able to try something like this:

fun <K, V> IsoMutableMap<K, V>.makeMap(): IsolateState<MutableMap<K, V>> = access { IsolateState(fork(mutableMapOf<K, V>())) }

Then your type would be

val nested = IsoMutableMap<Int, IsolateState<MutableMap<K, V>>>()

There's probably a better way to handle it, but I haven't done a ton of iso state in a while

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants