Skip to content

Watch sends interrupt signal right away in v3.43.x #2202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
davidkuridza opened this issue Apr 23, 2025 · 4 comments · May be fixed by #2271
Open

Watch sends interrupt signal right away in v3.43.x #2202

davidkuridza opened this issue Apr 23, 2025 · 4 comments · May be fixed by #2271
Assignees
Labels
area: watcher Changes related to the Taskfile watcher.

Comments

@davidkuridza
Copy link

Description

Upgrading from v3.42.1 to v3.43.x (both .1 and .2) breaks the --watch functionality.

Using an older version, for example, v3.42.1, works as it should:

❯ task --version
Task version: v3.42.1 (h1:HOaFbZGLOrAy2V/dLsX2rGJZVG2Qx6268KUIAIXdNE4=)

❯ task run -w
task: Started watching for tasks: run
task: [build] go build -o ./hello main.go
task: [run] ./hello
2025/04/23 16:39:27 INFO starting ...
# runs until manually cancelled, e.g. with `ctrl+c`

With v3.43.x, the following happens:

❯ task --version
3.43.2

❯ task run -w
task: Started watching for tasks: run
task: [build] go build -o ./hello main.go
task: [run] ./hello
2025/04/23 16:38:46 INFO starting ...
2025/04/23 16:38:46 INFO received interrupt signal, shutting down
2025/04/23 16:38:46 INFO stopped
task: task "run" finished running

The behaviour is the same using the Homebrew version as well as from source.

The above output is from the following Go code:

package main

import (
	"context"
	"log/slog"
	"os"
	"os/signal"
	"syscall"
)

func main() {
	if err := run(context.Background()); err != nil {
		slog.Error("could not run application", "err", err)
		os.Exit(1)
	}
}

func run(ctx context.Context) error {
	done := make(chan error, 1)
	go func() {
		sigint := make(chan os.Signal, 1)
		signal.Notify(sigint, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGQUIT)
		<-sigint
		slog.Info("received interrupt signal, shutting down")
		close(done)
	}()

	slog.Info("starting ...")

	if err := <-done; err != nil {
		return err
	}

	slog.Info("stopped")
	return nil
}

Version

v3.43.x

Operating system

all

Experiments Enabled

No response

Example Taskfile

version: "3"

interval: "500ms"

tasks:
  run:
    deps:
      - build
    cmds:
      - ./hello

  build:
    cmds:
      - go build -o ./hello main.go
    sources:
      - "./**/*.go"
    generates:
      - ./hello
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Apr 23, 2025
@andreynering andreynering added area: watcher Changes related to the Taskfile watcher. and removed state: needs triage Waiting to be triaged by a maintainer. labels Apr 23, 2025
@andreynering andreynering self-assigned this Apr 23, 2025
@noahfraiture
Copy link

noahfraiture commented Apr 29, 2025

I can confirm that the watch is broken

version: "3"

tasks:
  tailwind:
    desc: Build the style.css from classes found in templ files
    cmd: tailwindcss -i ./static/css/input.css -o ./static/css/style.css --minify
    sources:
      - ./templates/**/*.templ
    generates:
      - ./static/css/style.css

  templ:
    desc: Generate the templ files
    cmd: templ generate
    sources:
      - ./templates/**/*.templ
    generates:
      - ./templates/**/*_templ.go

  sqlc:
    desc: Generate Go code from raw SQL
    cmd: sqlc generate
    sources:
      - ./internal/db/queries/*.sql
    generates:
      - ./internal/db/generated/*.sql.go

  build:
    desc: Build the Go binary
    cmd: go build -o ./tmp/main ./cmd/nexzap/main.go
    deps:
      - templ
      - sqlc
      - tailwind
    sources:
      - ./go.mod
      - ./go.sum
      - ./cmd/**/*.go
      - ./internal/**/*.go
      - ./templates/**/*_templ.go
      - ./static/css/style.css
      - ./internal/db/migrations/*.sql
      - ./tutorials/**/*
    generates:
      - ./tmp/main

  run:
    desc: Run the built binary
    deps:
      - build
    cmd: ./tmp/main

  default:
    desc: Run the full build and start the program
    deps:
      - run

When running task -w either the /tmp/main doesn't even have the time to start, or is shutdown instantly

@pot-code
Copy link

pot-code commented May 9, 2025

+1 same

@andreynering andreynering linked a pull request May 27, 2025 that will close this issue
@andreynering
Copy link
Member

I opened #2271 that intends to fix this. Please give it a try and let me know if it's working for you.

@davidkuridza
Copy link
Author

Works better, but still not quite as it should. It works when first invoking it, but then starts either sending the signal or looping after a while. I've tested it with the following version:

./bin/task --version
3.43.3+de7ecf1

Below's a bit more complex example, where it doesn't work at all (works with 3.41.2). It gets stuck at npx ... step.

Another interesting thing is, if I run it with task run --force and then task run -w, it sometimes loops until I cancel it. It randomly works, but only for a change or two, then it loops again.

---

# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'

interval: 500ms

env:
  PACKAGE:
    sh: awk '/module/ {print $NF}' ./src/go.mod

tasks:
  default:
    silent: true
    cmd: task --list

  build:
    desc: Build the service
    label: "{{.ALIAS}}"
    dir: ./src
    deps:
      - generate:templ
      - generate:ui
    cmds:
      - rm -f ./bin/hello
      - go build -o ./bin/hello {{.PACKAGE}}/cmd
    sources:
      - "./go.mod"
      - "./go.sum"
      - "./**/*.go"
      - ./ui/assets/css/main.css
    generates:
      - ./bin/hello

  generate:templ:
    desc: Generate templates
    label: "{{.ALIAS}}"
    dir: ./src
    cmds:
      - find ./ -type f -name '*_templ.go' -delete
      - templ generate --path ./
    sources:
      - ./ui/**/*.templ
    generates:
      - ./ui/**/*_templ.go
    internal: true

  generate:ui:
    desc: Generate UI
    label: "{{.ALIAS}}"
    dir: ./src
    deps:
      - ui:deps
    cmds:
      - npx @tailwindcss/cli -i ./ui/assets/css/input.css -o ./ui/assets/css/main.css
    sources:
      - ./ui/assets/css/input.css
      - ./ui/**/*.templ
    generates:
      - ./ui/assets/css/main.css
    internal: true

  ui:deps:
    desc: Install UI dependencies
    cmd: npm install
    dir: ./src
    sources:
      - ./package.json
    generates:
      - ./node_modules
      - ./package-lock.json
    internal: true

  run:
    desc: Run the service
    label: "{{.ALIAS}}"
    dir: ./src
    deps:
      - build
    cmd: ./bin/hello {{.CLI_ARGS}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: watcher Changes related to the Taskfile watcher.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants