Hi guys, I think we ran into a problem reported he...
# arrow
d
Hi guys, I think we ran into a problem reported here: https://github.com/arrow-kt/arrow/issues/2375
I left a comment in the issue but we were chasing a few nodes that every now and then would have problems bootstrapping.
It looks like a dead lock initializing the companion objects of Either. I haven’t looked into the details but I’m guessing companion objects have a lock and the companion objects Left and Right can deadlock?
Looking at the impl it looks like the problem is the reference of the Either companion object to Left and Right. Ok, so under the hood it's a static variable referencing a subclass and potentially deadlocking by the class loader.
s
Hey @Daniel Berg, Thanks for sharing your findings. This issue is really shocking to me! In Arrow
0.11.x
Right
and
Left
are also "inner" classes of
sealed class Either
. They should however be
static
inner classes on the JVM because they're subtypes of the
sealed class
, and neither defines themselves as
inner class
. Looking at the Show Kotlin Bytecode feature in IntelliJ I don't see any synchronization/locks on the `Companion`s. Not to discredit your findings but I'm a bit stuck 😅
d
Yeah, this is indeed a surprise. I wish the compiler would throw a warning.
🔝 1
The problem is that the Left and Right references in the companion object of Either. Under the hood it's a static variable of an inner class that is a subclass of Either.
So the locking is done at the classloader.
I haven't checked the class loader but I assume it deadlocks 'cause it has to lock on the resolution of the symbols. Say, Right. It has to initialize it's parent class. But Either has then to initialize the static variables in order they're listed. On different threads they'll deadlock.
s
Right, that should easily be fixable then 🙂 I replied on the original ticket. We were planning to do a 0.13.x release this week so we can get it in there as well, and I'll backport this fix to 0.12.x too.
d
Oh cool! You're guys are so fast.
Thanks @simon.vergauwen! Again.
s
Yes, that seems to be a correct deduction of what is happening. Good thing we have a small test case that helps us reproduce this easily 🙂
Thanks for helping debug and report so we can move fast! arrow
👍 1
d
About time I setup the arrow build on my local machine 😉
Not sure if that's the direction you wanna go but I was able to reproduce the deadlock without the changes on my local machine.