laravel-query-intellij icon indicating copy to clipboard operation
laravel-query-intellij copied to clipboard

PhpStorm freeze

Open smirok opened this issue 11 months ago • 30 comments

Hi! PhpStorm team is here!

We noticed that PhpStorm users experience freezes when using the "Laravel Query" plugin. The stack trace of the freeze is attached below. Most likely, the ReadAction called when initializing DbReferenceExpression takes too long.

Freeze for 40 seconds
IDE KILLED! Sampled time: 31900ms, sampling rate: 100ms, GC time: 177ms (0%), Class loading: 0%

The stack is from the thread that was blocking EDT
com.intellij.diagnostic.Freeze
	at [email protected]/jdk.internal.misc.Unsafe.park(Native Method)
	at [email protected]/java.util.concurrent.locks.LockSupport.park(LockSupport.java:341)
	at [email protected]/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionNode.block(AbstractQueuedSynchronizer.java:506)
	at [email protected]/java.util.concurrent.ForkJoinPool.compensatedBlock(ForkJoinPool.java:3451)
	at [email protected]/java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3434)
	at [email protected]/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1623)
	at [email protected]/java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:420)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.lambda$call$0(JobLauncherImpl.java:486)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask$$Lambda$5940/0x0000000802b1f650.run(Unknown Source)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
	at com.intellij.openapi.progress.impl.CoreProgressManager$$Lambda$1465/0x000000080109e5d0.compute(Unknown Source)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:684)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:78)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.call(JobLauncherImpl.java:483)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.call(JobLauncherImpl.java:471)
	at [email protected]/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1428)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at [email protected]/java.util.concurrent.ForkJoinPool.helpJoin(ForkJoinPool.java:1883)
	at [email protected]/java.util.concurrent.ForkJoinTask.awaitDone(ForkJoinTask.java:440)
	at [email protected]/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:687)
	at [email protected]/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159)
	at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173)
	at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
	at [email protected]/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at dev.ekvedaras.laravelquery.utils.ResolverForColumnMethods$withOnePart$1.invoke(DbReferenceResolver.kt:129)
	at dev.ekvedaras.laravelquery.utils.ResolverForColumnMethods$withOnePart$1.invoke(DbReferenceResolver.kt:124)
	at dev.ekvedaras.laravelquery.utils.ResolverForColumnMethods.withOnePart$lambda$0(DbReferenceResolver.kt:124)
	at dev.ekvedaras.laravelquery.utils.ResolverForColumnMethods$$Lambda$8826/0x00000008034c8990.accept(Unknown Source)
	at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at [email protected]/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at [email protected]/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
	at [email protected]/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at [email protected]/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:686)
	at [email protected]/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159)
	at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173)
	at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
	at [email protected]/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at dev.ekvedaras.laravelquery.utils.ResolverForColumnMethods.withOnePart(DbReferenceResolver.kt:124)
	at dev.ekvedaras.laravelquery.utils.ResolverForColumnMethods.resolve(DbReferenceResolver.kt:111)
	at dev.ekvedaras.laravelquery.utils.DbReferenceResolver.resolve(DbReferenceResolver.kt:33)
	at dev.ekvedaras.laravelquery.models.DbReferenceExpression._init_$lambda$1(DbReferenceExpression.kt:61)
	at dev.ekvedaras.laravelquery.models.DbReferenceExpression$$Lambda$8801/0x00000008034aeaf0.run(Unknown Source)
	at com.intellij.openapi.application.impl.RwLockHolder.runReadAction(RwLockHolder.kt:254)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:833)
	at dev.ekvedaras.laravelquery.models.DbReferenceExpression.<init>(DbReferenceExpression.kt:59)
	at dev.ekvedaras.laravelquery.inspection.UnknownColumnInspection$buildVisitor$1.visitPhpStringLiteralExpression(UnknownColumnInspection.kt:50)
	at com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl.accept(StringLiteralExpressionImpl.java:45)
	at com.jetbrains.php.lang.psi.elements.impl.PhpPsiElementImpl.accept(PhpPsiElementImpl.java:117)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner$InspectionProblemHolder.visitElement(InspectionRunner.java:589)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner.processContext(InspectionRunner.java:408)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner.lambda$inspect$7(InspectionRunner.java:177)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner$$Lambda$6216/0x0000000802c8fbf0.run(Unknown Source)
	at com.intellij.openapi.application.impl.RwLockHolder.tryRunReadAction(RwLockHolder.kt:310)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:951)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner.lambda$executeInImpatientReadAction$17(InspectionRunner.java:371)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner$$Lambda$6225/0x0000000802c924f0.compute(Unknown Source)
	at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:158)
	at com.intellij.util.AstLoadingFilter.forceAllowTreeLoading(AstLoadingFilter.java:150)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner.lambda$executeInImpatientReadAction$18(InspectionRunner.java:362)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner$$Lambda$6220/0x0000000802c91960.compute(Unknown Source)
	at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:129)
	at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:118)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner.executeInImpatientReadAction(InspectionRunner.java:362)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner.lambda$inspect$8(InspectionRunner.java:176)
	at com.intellij.codeInsight.daemon.impl.InspectionRunner$$Lambda$5892/0x0000000802aeb498.process(Unknown Source)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.lambda$call$0(JobLauncherImpl.java:494)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask$$Lambda$5940/0x0000000802b1f650.run(Unknown Source)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
	at com.intellij.openapi.progress.impl.CoreProgressManager$$Lambda$1465/0x000000080109e5d0.compute(Unknown Source)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:78)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.call(JobLauncherImpl.java:483)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.call(JobLauncherImpl.java:471)
	at [email protected]/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1428)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at [email protected]/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at [email protected]/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at [email protected]/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at [email protected]/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

smirok avatar Mar 08 '24 14:03 smirok

If only I would know how to address that 😄 Is your DB very big or something?

ekvedaras avatar Mar 08 '24 14:03 ekvedaras

It isn't my stacktrace and I can't get any information about the DB size, but I do expect that the user's DB is quite large)

I can say that in this case, the UI thread required a write action, but was unable to obtain a write lock, as at that time, the heavy DbReferenceResolver.resolve operation was executed inside a runReadAction call on a background thread.

I assume there is no need to call runReadAction here if read access is allowed. It might be done otherwise, if it's necessary according to the code logic.

Something like this perhaps would work:

        if (!DumbService.isDumb(project)) {
            if (ApplicationManager.getApplication().isReadAccessAllowed) {
                TableAndAliasCollector(this).collect()
                DbReferenceResolver(this).resolve()
            } else { // if you need it
                ApplicationManager.getApplication().runReadAction {
                    TableAndAliasCollector(this).collect()
                    DbReferenceResolver(this).resolve()
                }
            }
        }

If it doesn't help, I would suggest using cancellable read actions (see https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html#read-action-cancellability) or decomposing DbReferenceResolver.resolve into several steps and calling each of them as a separate runReadAction.

smirok avatar Mar 10 '24 21:03 smirok

Thanks, very helpful 🙂 I will try your suggestion. If all checks pass, will release

ekvedaras avatar Mar 11 '24 05:03 ekvedaras

One a second thought, I've realized that the code snippet from above doesn't prevent freezing, sorry for the confusion.

I definitely recommend then to use a ReadAction.nonBlocking() from https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html#read-action-cancellability

smirok avatar Mar 11 '24 07:03 smirok

If I use something like this:

ReadAction.nonBlocking<Unit> {
    TableAndAliasCollector(this).collect()
    DbReferenceResolver(this).resolve()
}

it doesn't seem to run if I call myFixture.completeBasic() in tests. What am I missing?

ekvedaras avatar Mar 12 '24 18:03 ekvedaras

Does this not run only in tests or in PhpStorm too?

smirok avatar Mar 13 '24 11:03 smirok

I'm seeing PhpStorm 2024.1 (241.14494.237) hanging when editing SQL INSERT INTO VALUEs.

E.g.:

DB::insert('INSERT INTO table (t_id, name, description) VALUES (**hang when typing here**)');

Disabled all downloaded plugins. Then slowly re-enabled all plugins not related to PHP, then a few of the PHP plugins, and finally the most relatedly looking (this plugin).

Still not seeing the hanging behaviour anymore. So I guess there is some race condition based on hooking ordering, influenced by what order you enabled the plugins. Still seems stable after PhpStorm restarts.

I don't think the per project .idea\laravel-query-settings.xml has any influence, since the file is unchanged since last year for me.

HenkPoley avatar Apr 10 '24 07:04 HenkPoley

Facing the same issue, I can't even work 5 minutes on Phpstorm and it freezes. no click possible, can't even click or close the PhpStorm, every time force OS to close the application.

jayantisuthar avatar May 23 '24 12:05 jayantisuthar

To the topic "race condition": for me, it seemed there is a relation between "AI Assistant" activated and not activated. When I tested the AI assistant for 7 days, I had many freezes. After the 7-days were over, my PHPStorm never freezes, regardless what I am doing. For test purposes I could activate the AI assistant again. Once activated, just less than 1 hour later I had the first freeze. Maybe it is the laravel plugin, but with more and more plugins activated the race condition seems to come more frequently.

sneakyx avatar May 28 '24 05:05 sneakyx

Hi @ekvedaras! This is PhpStorm team again. Do you have any updates on this issue? We see more and more users reporting that Laravel Query plugin freezes the IDE completely for them.

pestretsov avatar Jun 21 '24 08:06 pestretsov

Hey, sorry, hectic life 😃 To be honest I don't have enough knowledge about the platform to know how to fix this 🙂 It seems related to ReadAction call. I also do not experience this myself :/ Granted I don't use AI assistant, just those single line completions. That read action scans code to find related statements to understand the query being built and link it to the right symbols in database. Maybe AI assistant gives the scan more work than it would need or vice versa 🤷

ekvedaras avatar Jun 21 '24 09:06 ekvedaras

Hi @ekvedaras! Have you tried the suggested approach?

smirok avatar Jun 21 '24 21:06 smirok

Hi @ekvedaras! Have you tried the suggested approach?

Not entirely sure what it suggests apart form making it idempotent. I will try to investigate a bit more tomorrow. If you have any more pointers, happy to hear them :)

ekvedaras avatar Jun 24 '24 10:06 ekvedaras

Have published v4.0.3 with a potential fix. It should be released soon.

ekvedaras avatar Jun 24 '24 19:06 ekvedaras

Hello, With the plugin enabled and updated to 4.0.3 + latest phpstorm, I've got a freeze almost instantly when opened a file with database queries (and refreshed the database connection). With the plugin disabled, everything works ok.

P.S. the plugin is super useful so thanks for the work you are doing on it and it would be awesome if this issue got fixed

andreigabreanu avatar Jun 25 '24 11:06 andreigabreanu

In order to test in later versions of phpstorm it seems like I need to do a bunch of upgrades in the plugin. Obviously various things break left and right 🙃 Might take more time

ekvedaras avatar Jun 25 '24 19:06 ekvedaras

It was mentioned I think that it may relate to AI assistant being enabled. My trial is expired so no clue how to test with it... 😄 As much as I test, everything works with no freezing 🤷

ekvedaras avatar Jun 25 '24 20:06 ekvedaras

Hi, I just wanted to share my experience with PhpStorm freezing on Ubuntu.

Whenever it's completely frozen, I use the command kill -9 $(pgrep -f phpstorm) to force it to close.

I've noticed that the freezing issue occurs specifically when I open a private Laravel library. This library includes only "illuminate/support" in its composer.json and does not have a .env file, which means there's no database connection. I often manipulate query builders in this library, and the freeze consistently occurs within files containing a $query instance. This leads me to believe that the absence of a database connection might be triggering the freezes.

Uninstalling the "Laravel Query" plugin resolved the issue for me. I hope this information proves useful.

jacobp3f avatar Jun 27 '24 13:06 jacobp3f

Hi to provide more context. I've been redirected here from reddit.

As I'm using the https://github.com/roblesterjr04/EloquentSalesForce plugin, I think this may make it crash too as If I remember correctly I've experienced these freezes only on the project where this plugin is used. Can it be that it times out because it can't reach salesforce to perform the query.

danielpetrica avatar Jul 01 '24 10:07 danielpetrica

Let's see if v4.0.4 helps

ekvedaras avatar Jul 02 '24 19:07 ekvedaras

Unfortunately it didn't work in my case. I enabled the plugin, updated it from version 4.0.2 to 4.0.4 and restarted the IDE. After clicking Refresh on the Database tab to see the new tables and interface ide hangs on all open windows. This is so sad.

DmitrySkibitsky avatar Jul 05 '24 12:07 DmitrySkibitsky

Well, I'm out of options then 😄 I cannot reproduce and clearly do not have enough knowledge about this platform nor kotlin/java dev in general to find the issue. I know the code there is not the best, but without help I don't know what else to try 🙂 Find smart friends and send them here please 🙂

ekvedaras avatar Jul 05 '24 12:07 ekvedaras

@DmitrySkibitsky Hi! This is PhpStorm team once again. I was wondering if you encountered freezing issues when working with a local or remote database. Also, could you please provide me with an approximate estimate of the size of your database?

smirok avatar Jul 11 '24 10:07 smirok

@DmitrySkibitsky Hi! This is PhpStorm team once again. I was wondering if you encountered freezing issues when working with a local or remote database. Also, could you please provide me with an approximate estimate of the size of your database?

This is a local database with 400+ tables, some number of db views (less than 50). The size of databases is from 400mb to 3gb. If you need exact values, I can open a specific project that I am working on all the time, turn on the plugin, trigger a hang and provide exact values.

DmitrySkibitsky avatar Jul 12 '24 21:07 DmitrySkibitsky

I can confirm it still freezes: this time I was in a class which has queries on the DB and I cmd+click a method to go to the definition. It jumped to the other file and everything froze.

andreigabreanu avatar Jul 13 '24 10:07 andreigabreanu

Some suggestions (not sure what's possible and what's not):

  • add try catch, disable plugin for current file on error
  • add timeout on plugin, so that timeout on IDE is not triggered
  • trigger alert on failed query; output query information for debugging

omarcinkonis avatar Jul 25 '24 07:07 omarcinkonis

4.0.4 - Freezes remained

pavelmgn avatar Aug 07 '24 05:08 pavelmgn

There's no cache, so every call (completion, inspection) calls the database. You need to use a cache, as the database doesn't change every minute, and at worst, an action that allows the user to invalidate the cache. The cache can be invalidated when a file is modified, so by making migration files dependent on the cache, it can be recalculated.

d3v2a avatar Aug 17 '24 04:08 d3v2a

Makes sense, but I doubt That is the problem. It would not freeze the UI. I've been using it with significant size projects and databases without a problem or any noticable slowdown 🤷

On Sat, Aug 17, 2024, 07:09 dev2a @.***> wrote:

There's no cache, so every call (completion, inspection) calls the database. You need to use a cache, as the database doesn't change every minute, and at worst, an action that allows the user to invalidate the cache. The cache can be invalidated when a file is modified, so by making migration files dependent on the cache, it can be recalculated.

— Reply to this email directly, view it on GitHub https://github.com/ekvedaras/laravel-query-intellij/issues/114#issuecomment-2294615832, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3LRCGE62J426YUNYEMRRDZR3EHLAVCNFSM6AAAAABEM3WQO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGYYTKOBTGI . You are receiving this because you modified the open/close state.Message ID: @.***>

ekvedaras avatar Aug 17 '24 04:08 ekvedaras

The latest version needs to be fixed. I used to love this plugin, but now it's unusable because every time I enable it, it causes PhpStorm to freeze. Earlier versions weren't as bad. What changed?

andrewdwallo avatar Aug 18 '24 19:08 andrewdwallo