1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix: use a fixed runner name for old (<= v1.20) Forgejo instances (#972)

The bug was already there before the recent refactor. Only it
manifested itself when shutting down the runner because
`resp.Msg.GetRunner().GetName()` was only called then. It was
correctly refactored in the createRunner function and therefore
surfaced because `resp.Msg.GetRunner().GetName()` was called
during initialization instead of during shutdown.

```
time="2025-09-10T05:41:10Z" level=info msg="log level changed to debug" func="[func2]" file="[daemon.go:130]"
time="2025-09-10T05:41:10Z" level=info msg="Starting runner daemon" func="[runDaemon]" file="[daemon.go:51]"
time="2025-09-10T05:41:10Z" level=warning msg="Because the Forgejo instance is an old version, skipping declaring the labels and version." func="[func6]" file="[daemon.go:208]"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xcc1a23]
goroutine 1 [running]:
code.forgejo.org/forgejo/runner/v11/internal/app/cmd.init.func6({0x111f428, 0xc0000e8ab0}, 0xc0003b4000, 0xc0003b8230, {0x1125eb8?, 0xc000424040?}, {0xc000032840, 0x6, 0x8})
	/srv/internal/app/cmd/daemon.go:222 +0x4a3
code.forgejo.org/forgejo/runner/v11/internal/app/cmd.runDaemon({0x111f578, 0xc00025fa00}, 0xc0000380b0)
	/srv/internal/app/cmd/daemon.go:68 +0x23f
code.forgejo.org/forgejo/runner/v11/internal/app/cmd.Execute.getRunDaemonCommandProcessor.func6(0xc000044d00?, {0xc0000c4360?, 0x4?, 0xf63e10?})
	/srv/internal/app/cmd/daemon.go:33 +0x1f
github.com/spf13/cobra.(*Command).execute(0xc0000fe908, {0xc0000c4340, 0x2, 0x2})
	/go/pkg/mod/github.com/spf13/cobra@v1.10.1/command.go:1015 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000fe008)
	/go/pkg/mod/github.com/spf13/cobra@v1.10.1/command.go:1148 +0x46f
github.com/spf13/cobra.(*Command).Execute(...)
	/go/pkg/mod/github.com/spf13/cobra@v1.10.1/command.go:1071
code.forgejo.org/forgejo/runner/v11/internal/app/cmd.Execute({0x111f578, 0xc00025fa00})
	/srv/internal/app/cmd/cmd.go:89 +0xa05
main.main()
	/srv/main.go:18 +0x7b
20250910 05:41:10 daemon: client (pid 4264) exited with 2 status, exiting
```

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/972): <!--number 972 --><!--line 0 --><!--description Zml4OiB1c2UgYSBmaXhlZCBydW5uZXIgbmFtZSBmb3Igb2xkICg8PSB2MS4yMCkgRm9yZ2VqbyBpbnN0YW5jZXM=-->fix: use a fixed runner name for old (<= v1.20) Forgejo instances<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/972
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-09-10 16:06:48 +00:00 committed by earl-warren
parent 4d98bda282
commit 16276cc0d6
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201

View file

@ -206,10 +206,12 @@ var createRunner = func(ctx context.Context, cfg *config.Config, reg *config.Reg
resp, err := runner.Declare(ctx, ls.Names()) resp, err := runner.Declare(ctx, ls.Names())
if err != nil && connect.CodeOf(err) == connect.CodeUnimplemented { if err != nil && connect.CodeOf(err) == connect.CodeUnimplemented {
log.Warn("Because the Forgejo instance is an old version, skipping declaring the labels and version.") log.Warn("Because the Forgejo instance is an old version, skipping declaring the labels and version.")
return runner, "runner", nil
} else if err != nil { } else if err != nil {
log.WithError(err).Error("fail to invoke Declare") log.WithError(err).Error("fail to invoke Declare")
return nil, "", err return nil, "", err
} else { }
log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully", log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully",
resp.Msg.GetRunner().GetName(), resp.Msg.GetRunner().GetVersion(), resp.Msg.GetRunner().GetLabels()) resp.Msg.GetRunner().GetName(), resp.Msg.GetRunner().GetVersion(), resp.Msg.GetRunner().GetLabels())
// if declared successfully, override the labels in the.runner file with valid labels in the config file (if specified) // if declared successfully, override the labels in the.runner file with valid labels in the config file (if specified)
@ -218,7 +220,6 @@ var createRunner = func(ctx context.Context, cfg *config.Config, reg *config.Reg
if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil {
return nil, "", fmt.Errorf("failed to save runner config: %w", err) return nil, "", fmt.Errorf("failed to save runner config: %w", err)
} }
}
return runner, resp.Msg.GetRunner().GetName(), nil return runner, resp.Msg.GetRunner().GetName(), nil
} }