Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Opening a Gradle build in IntelliJ IDEA spawns a Gradle daemon per previously open .gradle.kts script #942

Closed
eskatos opened this issue Jun 27, 2018 · 2 comments

Comments

@eskatos
Copy link
Member

eskatos commented Jun 27, 2018

Current Behavior

When opening a project that was previously closed with Gradle Kotlin DSL scripts open, IntelliJ IDEA reopens those scripts. This spawns a Gradle daemon per open Gradle Kotlin DSL script. Having tens of scripts open does sound reasonable.

On the other hand, when starting with no script opened and opening a bunch one after the other, a single Gradle daemon is spawn and reused properly.

What I think happens is that the dependencies of open scripts are all requested concurrently when a project is open. The Gradle daemon does not support concurrent Tooling API requests, so a new daemon is spawn to fulfill each request.

The daemons do expire quickly but until they are all done it puts a lot of stress on the system with processes eating memory, re-doing the same things, and, fighting for shared resources.

Steps to Reproduce (for bugs)

  • Import a Gradle build making use of the Kotlin DSL in IntelliJ IDEA
  • Open a bunch of .gradle.kts files
  • Close the project
  • Kill all Gradle daemons
  • Open the project
  • Observe one Gradle daemon being spawn per previously open script

Your Environment

I can reproduce this on various builds using Kotlin IntelliJ Plugin 1.2.50 or 1.2.60-eap-7.

Expected Behavior

Not a fork bomb.
A single Gradle daemon should be enough.

@eskatos
Copy link
Member Author

eskatos commented Jun 28, 2018

Logging static and instance invocation counters from the resolver it seems the IntelliJ Kotlin Plugin reuses the resolver instances per script template, instances are in isolated classloaders though. IOW, one classloader and resolver instance for all *.init.gradle.kts scripts, another one for all *.settings.gradle.kts scripts and another one for all *.gradle.kts.

The best we could do to mitigate the issue is to add a queue to our resolver. There still would be room for 3 concurrent TAPI requests across script templates. Not perfect, but not a fork bomb anymore.

@eskatos eskatos changed the title Opening a Kotlin DSL build in IntelliJ IDEA spawns a Gradle daemon per previously open script Opening a Gradle build in IntelliJ IDEA spawns a Gradle daemon per previously open .gradle.kts script Jun 28, 2018
@eskatos eskatos added this to the 0.19.x milestone Jun 28, 2018
@bamboo bamboo self-assigned this Jun 28, 2018
bamboo added a commit that referenced this issue Jun 28, 2018
In order to avoid spawning a Gradle daemon per open .gradle.kts
script.

See #942
@bamboo
Copy link
Member

bamboo commented Jun 28, 2018

Fixed in 4f0c82f.

@bamboo bamboo closed this as completed Jun 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants