Skip to content

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

@davidkuridza

Description

@davidkuridza

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

Metadata

Metadata

Assignees

Labels

area: watcherChanges related to the Taskfile watcher.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions