playframework icon indicating copy to clipboard operation
playframework copied to clipboard

Server stops immediately when runPlay is run from another tasks

Open cataphract opened this issue 4 years ago • 4 comments

Gradle 6.6.1. Version 0.10

Not sure what's going on here. The application runs fine from the distribution tar and if runPlay is called directly. I can see that the server starts and that port 8080 is bound but then PlayWorkerServer::stop() is called.

// TOP project
def jvmArgs = /* ... */
def createSampleAppTarget = { name, target ->
    tasks.create(name: name, type: GradleBuild, dependsOn: shadowJar) {
        description = "Run $target with instrumentation"
        group = 'application'

        startParameter = startParameter.newInstance()
        startParameter.projectProperties = [
                jvmArgs       : "-javaagent:$shadowJar.archivePath $jvmArgs",
                debugJvm      : project.hasProperty('debugJvm') ? project.debugJvm : 'false',
        ]
        tasks = [target]
    }
}

createSampleAppTarget 'runInstrumentedPlayApp', ':samplePlayApp:runPlay'
// SUBPROJECT
runPlay {
    httpPort = 8080

    // TODO: possible to change executable? doesn't look like so
    def jvmArgs = []
    if (project.hasProperty('jvmArgs')) {
        jvmArgs += (project.jvmArgs.split(/\s+/) as List)
    }

    if (project.hasProperty('debugJvm') && project.debugJvm == 'true') {
        jvmArgs += ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0:5005']
    }
    forkOptions.jvmArgs = jvmArgs
}

I can't reproduce this is the task that calls the runPlay task is in the same project.

cataphract avatar Nov 16 '20 16:11 cataphract

I think I've reproduced this within the same project and can't yet grasp the issue here:

task debugPlay {
    def runPlayTask = tasks.findByName('runPlay')
    runPlayTask.forkOptions.jvmArgs = ['-Xdebug', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999']
    doLast {
        runPlayTask.run()
    }
}

seems to be simple approach to debugging, but play stops immediately.

maiksaray avatar Nov 28 '20 15:11 maiksaray

And it was pretty easy to get what's happening from here. The issue is that runPlay task specifies file input tracking to trigger continuous build in gradle and it stays running. Custom tasks that just run runPlay do not and they just end. I specified inputs.files(runPlayTask.getAssetsDirs()) in my debugPlay configuration (actually I don't think it matters what to track here) and got task hanging there in continuous build.
Hope this helps @cataphract

Not sure this can be / should be fixed in plugin (however debug task would be nice)

maiksaray avatar Nov 28 '20 15:11 maiksaray

I think I've reproduced this within the same project and can't yet grasp the issue here:

task debugPlay {
    def runPlayTask = tasks.findByName('runPlay')
    runPlayTask.forkOptions.jvmArgs = ['-Xdebug', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999']
    doLast {
        runPlayTask.run()
    }
}

seems to be simple approach to debugging, but play stops immediately.

Does this mean you all are able to set debug breakpoints using this setup? I'm trying to get the same going over command line with : GRADLE_OPTS="-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" gradle --no-daemon run but never hitting the breakpoint in intellij

[UPDATE] In the end this setup worked for me: $ gradle runPlay -Ddebug=true

play {
    injectedRoutesGenerator = true
    platform {
        playVersion = playV
        scalaVersion = scalaV
        javaVersion = javaV
        if (System.getProperty("debug")) {
            def runPlayTask = tasks.findByName('runPlay')
            runPlayTask.forkOptions.jvmArgs = ['-Xdebug', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005']
        }
    }
}

if you don't want the daemon to wait for connection just flipt the jwdt suspend to n: runPlayTask.forkOptions.jvmArgs = ['-Xdebug', '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005']

devYonz avatar Dec 19 '20 18:12 devYonz

@yfeleke long time passed but maybe you remember if you did this and used the remote debug in intellij or simply local debug ?

Thanks

Jonatha1983 avatar May 10 '22 14:05 Jonatha1983