air-verse / air

☁️ Live reload for Go apps
GNU General Public License v3.0
16.32k stars 770 forks source link

Process is orphaned rather than shut down when air exits #614

Closed quinn closed 1 week ago

quinn commented 3 weeks ago

My command looks like this:

cmd = "tailwindcss -o public/css/styles.css && templ generate && go build -o ./tmp/main cmd/main.go"

Version:

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.52.2, built with Go go1.22.4

I found this PR that might be related: https://github.com/air-verse/air/pull/254

Hbbb commented 3 weeks ago

FWIW, I have the same issue. Same version of Air.

marco-souza commented 2 weeks ago

I had the same issue a few weeks ago. My workaround was to kill the old dangling process before starting the new one - ref

davidedpg10 commented 2 weeks ago

Does anyone know a good fix for this? I'm also encountering the same issue with orphaned processes, and it's very annoying manually killing a process every couple of minutes

silverwind commented 1 week ago

Duplicate of https://github.com/air-verse/air/issues/534.

It appears the issue is exclusively limited to MacOS.

nakkamarra commented 1 week ago

Just curious, what CPU are you using?

quinn commented 1 week ago

apple arm cpu.

I've stopped using air, instead using go Task:

version: "3"

vars:
  NAME: "my-app-name"
  BIN_NAME: "{{.NAME}}_bin"

tasks:
  dev:
    desc: Run app in development mode with reload
    watch: true
    sources:
      - "**/*.go"
      - "**/*.templ"
      - exclude: "views/*_templ.go"
    deps:
      - kill
      - templ
      - css
    cmds:
      - go build -o ./tmp/{{.BIN_NAME}} cmd/main.go
      - ./tmp/{{.BIN_NAME}} webserver
    status: ["false"]

  kill:
    cmds:
      - killall -q {{.BIN_NAME}} || echo "Process was not running."

  templ:
    cmds:
      - templ generate

  css:
    cmds:
      - tailwindcss -o public/css/styles.css

this has been working reliably for me.

nakkamarra commented 1 week ago

I am fairly certain this is related to apple silicon, I am unable to reproduce on intel CPU and ARM seems to be consistently reproducible

quinn commented 1 week ago

Closing this because switching to Task has resolve it for me and there is #534 already

davidedpg10 commented 1 week ago

My OS is CentOS 9, and running on a Proxmox VM on a Dell R720 which has Intel Xeon CPUs

I believe part of the issue is that air init creates the initial air file, however it fills bin but not full_bin, which I think might be causing some issues. For a while I had to do the following so it would cleanup the process post kill:

post_cmd = ["kill -9 $(lsof -t -i:3000)"]

but the behavior was inconsistent.