Skip to content

gitlab-runner windows issue with locked config.toml

Summary

Starting with gitlab-runner version v12.2.0-rc1, I'm encountering issues on several Windows clients which have the gitlab-runner installed. Attempting to execute commands via. gitlab-runner.exe results in errors due to the config.toml being locked once the gitlab-runner service is installed and running.

Steps to reproduce

C:\Users\user\Desktop>gitlab-runner-windows-amd64.exe install
  • Start service
C:\Users\user\Desktop>gitlab-runner-windows-amd64.exe start
Runtime platform                                    arch=amd64 os=windows pid=2964 revision=a987417a version=12.2.0
  • Attempt to register a runner: gitlab-runner register

What is the current bug behavior?

Any operation concerning the config.toml file will fail, e.g simply trying to view the file:

C:\Users\user\Desktop>type config.toml
The process cannot access the file because another process has locked a portion of the file.

Registering a runner:

C:\Users\user\Desktop>gitlab-runner-windows-amd64.exe register
Runtime platform                                    arch=amd64 os=windows pid=3812 revision=a987417a version=12.2.0
PANIC: read C:\Users\user\Desktop\config.toml: The process cannot access the file because another process has locked a portion of the file.

Runner verify:

C:\Users\user\Desktop>gitlab-runner-windows-amd64.exe verify
Runtime platform                                    arch=amd64 os=windows pid=2992 revision=a987417a version=12.2.0
FATAL: read C:\Users\user\Desktop\config.toml: The process cannot access the file because another process has locked a portion of the file.

Even though one might say that you should not start the gitlab-runner service immediately after installing the runner, this will still hit you later on. Imagine you have a runner registered that you then delete from the GitLab UI, when you then attempt to cleanup via.:

C:\Users\user\Desktop>gitlab-runner-windows-amd64.exe verify --delete
Runtime platform                                    arch=amd64 os=windows pid=2992 revision=a987417a version=12.2.0
FATAL: read C:\Users\user\Desktop\config.toml: The process cannot access the file because another process has locked a portion of the file.

The workaround here would be, to stop the gitlab-runner service before executing the verify --delete command. However, that would mean that you completely stop your runner machine from being usable, as to my understanding stopping the runner service will result in the whole machine being unavailable to GitLab.

What is the expected correct behavior?

Command executes successfully, even when the Windows "gitlab-runner" service is currently running, as this worked up until version v12.2.0-rc1 of the runner.

Possible fixes

I have a suspicion, that this might possibly be related to the changes introduced in !1496 (merged). It appears to me as if the config.toml is locked, due to the active Windows service.