From 16276cc0d6f8c345d25fe2ef2222cf9dfe44abec Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 10 Sep 2025 16:06:48 +0000 Subject: [PATCH] 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 ``` - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/972): fix: use a fixed runner name for old (<= v1.20) Forgejo instances Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/972 Reviewed-by: Michael Kriese Reviewed-by: Mathieu Fenniak Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- internal/app/cmd/daemon.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/app/cmd/daemon.go b/internal/app/cmd/daemon.go index d864af82..4edf2dbe 100644 --- a/internal/app/cmd/daemon.go +++ b/internal/app/cmd/daemon.go @@ -206,18 +206,19 @@ var createRunner = func(ctx context.Context, cfg *config.Config, reg *config.Reg resp, err := runner.Declare(ctx, ls.Names()) if err != nil && connect.CodeOf(err) == connect.CodeUnimplemented { log.Warn("Because the Forgejo instance is an old version, skipping declaring the labels and version.") + return runner, "runner", nil } else if err != nil { log.WithError(err).Error("fail to invoke Declare") return nil, "", err - } else { - log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully", - 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) - runner.Update(ctx, ls) - reg.Labels = ls.ToStrings() - if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { - return nil, "", fmt.Errorf("failed to save runner config: %w", err) - } + } + + log.Infof("runner: %s, with version: %s, with labels: %v, declared successfully", + 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) + runner.Update(ctx, ls) + reg.Labels = ls.ToStrings() + if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { + return nil, "", fmt.Errorf("failed to save runner config: %w", err) } return runner, resp.Msg.GetRunner().GetName(), nil }