metalbear-co / mirrord

Connect your local process and your cloud environment, and run local code in cloud conditions.
https://mirrord.dev
MIT License
3.6k stars 100 forks source link

Process killed when live-reload quarkus Java application #2360

Open vanduc2514 opened 2 months ago

vanduc2514 commented 2 months ago

Bug Description

I used mirrord to start a quarkus Java application in dev mode for live reloading of the application in development. And I use VSCode in devcontainer for my local development workspace. After a while of implementing, my VSCode freezes and the Java process is killed, along with the agent

Command to start quarkus Java application

mirrord -f .mirrord/mirrord.json mvn quarkus:dev

Mirrord configuration

{
    "target": {
        "namespace": "dev",
        "path": {
            "deployment": "service-ext-deployment-dev"
        }
    },
    "feature": {
      "env": true,
      "fs": "read",
      "network": true
    },
    "internal_proxy": {
      "log_destination": "/tmp/internal_proxy.log",
      "log_level": "mirrord=trace"
    }
  }

launch.json for attaching the local debugger

{
            "type": "java",
            "request": "attach",
            "hostName": "localhost",
            "name": "Attach Debugger",
            "port": 5005,
            "projectName": "service"
}

The trace log is large so I attached it below

internal_proxy.log

Steps to Reproduce

  1. Use VSCode IDE
  2. Run Quarkus dev mode in VSCode
  3. Place breakpoint
  4. Live-reload Quarkus by modifying source

Backtrace

No response

Relevant Logs

No response

Your operating system and version

java GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30)

Local process

java

Local process version

java 17 grralvm

Additional Info

However, if I start a new bash session using mirrord

mirrord -f .mirrord/mirrord.json bash

Then run the quarkus Java application in dev mode

mvn quarkus:dev

Then the above issue never happens, the performance is better, VSCode does not freeze and the Java process is not killed

aviramha commented 2 months ago

Thanks for reporting this! This seems to happen because of idle_timeout. The internal proxy component (part that runs on your machine) aggregates "layer" (the part that loads into your local process) connections. When there are no connections for a said duration, it cleans up. I assume the issue is that sometimes the reload time > idle_timeout which means that until the new connection is established the internal proxy already dies. You can control that timeout by setting

"internal_proxy": {"idle_timeout": 10}

The timeout is in seconds, and by default it is 5 seconds. Can you try increasing it and seeing if it happens again?

vanduc2514 commented 2 months ago

Actually I increased the idle_timeout to 1200 (20 minutes) but the issue can still be reproduced. It usually happens if I have a compilation error in my VSCode IDE when writing some code. I use autosave feature of VSCode and the IDE compile the code everytime the file is saved automatically.

Also, the performance in VSCode is greatly impact, much slower, compare to using mirrord exec bash then run the Quarkus application in the terminal. So I guess because Quarkus is executed using launch configuration in VSCode, so the application is executed by mirrord but from a process that VSCode created. VSCode can control mirrord from its spawned process, hence it can kill mirrord execution.

I haven't tried with manul saving (manual compilation) in VSCode but I doubt it will work, since there is less synchronization happening.

aviramha commented 2 months ago

Can you attach the same log as above reproduced with the new idle timeout please?

vanduc2514 commented 2 months ago

Sure, this is the trace log

internal_proxy.log

And the configuration is

"internal_proxy": {
        "log_destination": "/tmp/internal_proxy.log",
        "log_level": "mirrord=trace",
        "idle_timeout": 1200
}
aviramha commented 2 months ago

I see it fails on accessing /workspace because it tries to read it from remote. Can you try to add it to local path?

{
  "feature": {
    "fs": {
      "mode": "read",
      "local": ["/workspace.+"]
    }
  }
}
vanduc2514 commented 2 months ago

I tried with the above configuration, Quarkus process did not get killed this time but the performance of VSCode is much slower or freeze for code completion, suggestion, compare to not using that configuration. Sometimes the VSCode debugger is even terminated while I write some code.

Increasing the memory of Java language server helped with the slowing / freezing of VSCode (not entirely) but I don't need to do that if I use mirrord to open a new shell and run Quarkus in development mode within that shell.

Do you think using the mirrord VSCode extension can help with this issue ?

aviramha commented 2 months ago

It could be that we're attached to the debugger as well, making it a bit slower. I'd try to use the extension to see if it helps.

eyalb181 commented 2 weeks ago

Hey @vanduc2514 , did using the extension help here?