Panic when executing gitlab-runner run-single
Summary
Panic caused by a <nil>
pointer dereference on gitlab-runner run-single
due to the lack of configuration.
Bug introduced with 87a01c63 from !3817 (merged); related to #29390 (closed).
Steps to reproduce
Registration
$ GITLAB_API_TOKEN={token} # where {token} is an API token in the form /glpat-.*/
$ GITLAB_PROJECT_SLUG={user}%2F{project} # where {user} and {project} are placeholders
$ GITLAB_RUNNERS_TOKEN=$(curl --header "Authorization: Bearer $GITLAB_API_TOKEN" "https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_SLUG" | jq --raw-output .runners_token)
$ GITLAB_RUNNER_REGISTRATION_TOKEN=$(curl --form token="$GITLAB_RUNNERS_TOKEN" https://gitlab.com/api/v4/runners | jq --raw-output .token)
Installation
go install
Using $ go install gitlab.com/gitlab-org/gitlab-runner@87a01c63 # or latest (536af644)
official builds
Using$ VERSION=latest # or v15.8.0 for reproducibility purposes
$ curl --location https://gitlab-runner-downloads.s3.amazonaws.com/$VERSION/binaries/gitlab-runner-linux-amd64 --output /bin/gitlab-runner
$ chmod a+x /bin/gitlab-runner
Execution
$ gitlab-runner run-single --executor=docker --url=https://gitlab.com --token=$GITLAB_RUNNER_REGISTRATION_TOKEN
Actual behavior
$ gitlab-runner run-single --executor=shell --url=https://gitlab.com --token=$GITLAB_RUNNER_REGISTRATION_TOKEN
Runtime platform arch=amd64 os=linux pid=6998 revision=HEAD version=development version
Starting runner for https://gitlab.com with token TVwf5PPv ...
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10c35d0]
goroutine 1 [running]:
main.main.func1()
/go/pkg/mod/gitlab.com/gitlab-org/gitlab-runner@v1.11.1-0.20230117110644-275ef741ca1e/main.go:40 +0x5e
panic({0x1ceca80, 0x33d95f0})
/usr/local/go/src/runtime/panic.go:884 +0x212
gitlab.com/gitlab-org/gitlab-runner/common.(*SystemIDState).GetSystemID(...)
/go/pkg/mod/gitlab.com/gitlab-org/gitlab-runner@v1.11.1-0.20230117110644-275ef741ca1e/common/system_id_state.go:28
gitlab.com/gitlab-org/gitlab-runner/network.(*GitLabClient).RequestJob(_, {_, _}, {{0x0, 0x0}, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...)
/go/pkg/mod/gitlab.com/gitlab-org/gitlab-runner@v1.11.1-0.20230117110644-275ef741ca1e/network/gitlab.go:415 +0x150
gitlab.com/gitlab-org/gitlab-runner/commands.(*RunSingleCommand).processBuild(0xc000122b40, {0x0, 0x0}, 0xc0004c0000)
/go/pkg/mod/gitlab.com/gitlab-org/gitlab-runner@v1.11.1-0.20230117110644-275ef741ca1e/commands/single.go:81 +0x105
gitlab.com/gitlab-org/gitlab-runner/commands.(*RunSingleCommand).Execute(0xc000122b40, 0x33e9bc0?)
/go/pkg/mod/gitlab.com/gitlab-org/gitlab-runner@v1.11.1-0.20230117110644-275ef741ca1e/commands/single.go:172 +0x5dd
github.com/urfave/cli.HandleAction({0x1bdd9e0?, 0xc000012468?}, 0xa?)
/go/pkg/mod/github.com/urfave/cli@v1.22.10/app.go:526 +0x7f
github.com/urfave/cli.Command.Run({{0x2016e93, 0xa}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x202885f, 0x13}, {0x0, ...}, ...}, ...)
/go/pkg/mod/github.com/urfave/cli@v1.22.10/command.go:173 +0x65b
github.com/urfave/cli.(*App).Run(0xc00001f180, {0xc0000520a0, 0x5, 0x5})
/go/pkg/mod/github.com/urfave/cli@v1.22.10/app.go:277 +0x8c7
main.main()
/go/pkg/mod/gitlab.com/gitlab-org/gitlab-runner@v1.11.1-0.20230117110644-275ef741ca1e/main.go:70 +0x2c8
Expected behavior
$ gitlab-runner run-single --executor=shell --url=https://gitlab.com --token=$ GITLAB_RUNNER_REGISTRATION_TOKEN
Runtime platform arch=amd64 os=linux pid=16928 revision=HEAD version=development version
Starting runner for https://gitlab.com with token TVwf5PPv ...
Checking for jobs...nothing runner=TVwf5PPv
GitLab Runner version
$ gitlab-runner --version
Version: 15.8.0
Git revision: 12335144
Git branch: 15-8-stable
GO version: go1.18.9
Built: 2023-01-19T03:18:22+0000
OS/Arch: linux/amd64
Edited by Helio Machado