EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.72k stars 287 forks source link

Infinite indexing in IntelliJ Ultimate 2022.2.4, MacOS Ventura 13.0.1 (deadlock detected by Yourkit) #510

Closed Techcable closed 1 year ago

Techcable commented 1 year ago

Environment(环境)

name version
IDEA version IntelliJ IDEA 2022.2.4 (Ultimate Edition)
EmmyLua version 1.3.7.2-IDEA222
OS MacOS Ventura 13.0.1

What are the steps to reproduce this issue?(重现步骤?)

  1. Clear caches & restart in IntelliJ Ultimate
  2. After clearing caches, open a Rust + Python project
  3. This will cause IntelliJ to re-index
  4. Project freezes [...]

What happens?(出现什么问题?)

The entire application freezes.

YourKit detects a deadlock in EmmyLua I've pasted below.

Disabling EmmyLua fixes the issue.

What were you expecting to happen?(期望?)

I can have EmmyLua enabled, and the application should still work.

Any logs, error output, etc?(有没有什么log, error输出?)

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

https://gist.github.com/Techcable/bd377d5688b771a16b47dde23d9da132

Any other comments?(其它说明)

Similar to some other issues. However, I am not sure its the same. Deadlocks can be very difficult to debug, so I thought I'd post the information YourKit identified.

It looks like the Ty class can't even finish running its class initializer <clinit> (link). This is caused by a deadlock in the static fields or a static { } block.

If the class initializer of Ty can't finish, nothing else in the Ty class can run!

Techcable commented 1 year ago

Based on the stack trace, it seems like the root of the problem is com.tang.intellij.lua.ty.Ty.<clinit>() at Ty.kt:198:

https://github.com/EmmyLua/IntelliJ-EmmyLua/blob/4d101b82ec81a129dab821d9b92d88fcffb47fd5/src/main/java/com/tang/intellij/lua/ty/Ty.kt#L198

I strongly suspect this triggers a dependency cycle in class initialization. If this is the case, consider using Kotlin's lazy properties.

I see Ty.<clinit> in the thread dumps of #459 , #482 . I suspect they have the same cause.

Possibly the cause of #429 , but the pastebin of the thread dump expired so I cannot tell.

CppCXY commented 1 year ago

can you make a pr fix this?

Techcable commented 1 year ago

Yes. I am working on it right now 😄 It looks like the issue is simple to fix!

If you look in stack you will also see waiting on the Class initialization monitor for com.tang.intellij.lua.ty.TyClass

Techcable commented 1 year ago

This is closed by #511