Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Seipel
gitlab-runner
Commits
080e3f1c
Commit
080e3f1c
authored
8 years ago
by
Alessio Caiazza
Committed by
Alessio Caiazza
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix race condition in single runner
parent
934a92ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
commands/single.go
+9
-8
9 additions, 8 deletions
commands/single.go
with
9 additions
and
8 deletions
commands/single.go
+
9
−
8
View file @
080e3f1c
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
log
"github.com/Sirupsen/logrus"
log
"github.com/Sirupsen/logrus"
"github.com/tevino/abool"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/network"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/network"
"os/signal"
"os/signal"
...
@@ -20,16 +21,16 @@ type RunSingleCommand struct {
...
@@ -20,16 +21,16 @@ type RunSingleCommand struct {
lastBuild
time
.
Time
lastBuild
time
.
Time
runForever
bool
runForever
bool
MaxBuilds
int
`long:"max-builds" description:"How many builds to process before exiting"`
MaxBuilds
int
`long:"max-builds" description:"How many builds to process before exiting"`
finished
bool
finished
*
a
bool
.
AtomicBool
}
}
func
waitForInterrupts
(
finished
*
b
ool
,
abortSignal
chan
os
.
Signal
,
doneSignal
chan
int
)
{
func
waitForInterrupts
(
finished
*
abool
.
AtomicB
ool
,
abortSignal
chan
os
.
Signal
,
doneSignal
chan
int
)
{
signals
:=
make
(
chan
os
.
Signal
)
signals
:=
make
(
chan
os
.
Signal
)
signal
.
Notify
(
signals
,
os
.
Interrupt
,
syscall
.
SIGTERM
,
syscall
.
SIGQUIT
)
signal
.
Notify
(
signals
,
os
.
Interrupt
,
syscall
.
SIGTERM
,
syscall
.
SIGQUIT
)
interrupt
:=
<-
signals
interrupt
:=
<-
signals
if
finished
!=
nil
{
if
finished
!=
nil
{
*
finished
=
true
finished
.
Set
()
}
}
// request stop, but wait for force exit
// request stop, but wait for force exit
...
@@ -108,11 +109,11 @@ func (r *RunSingleCommand) processBuild(data common.ExecutorData, abortSignal ch
...
@@ -108,11 +109,11 @@ func (r *RunSingleCommand) processBuild(data common.ExecutorData, abortSignal ch
func
(
r
*
RunSingleCommand
)
checkFinishedConditions
()
{
func
(
r
*
RunSingleCommand
)
checkFinishedConditions
()
{
if
r
.
MaxBuilds
<
1
&&
!
r
.
runForever
{
if
r
.
MaxBuilds
<
1
&&
!
r
.
runForever
{
log
.
Println
(
"This runner has processed its build limit, so now exiting"
)
log
.
Println
(
"This runner has processed its build limit, so now exiting"
)
r
.
finished
=
true
r
.
finished
.
Set
()
}
}
if
r
.
WaitTimeout
>
0
&&
int
(
time
.
Since
(
r
.
lastBuild
)
.
Seconds
())
>
r
.
WaitTimeout
{
if
r
.
WaitTimeout
>
0
&&
int
(
time
.
Since
(
r
.
lastBuild
)
.
Seconds
())
>
r
.
WaitTimeout
{
log
.
Println
(
"This runner has not received a job in"
,
r
.
WaitTimeout
,
"seconds, so now exiting"
)
log
.
Println
(
"This runner has not received a job in"
,
r
.
WaitTimeout
,
"seconds, so now exiting"
)
r
.
finished
=
true
r
.
finished
.
Set
()
}
}
return
return
}
}
...
@@ -135,16 +136,16 @@ func (r *RunSingleCommand) Execute(c *cli.Context) {
...
@@ -135,16 +136,16 @@ func (r *RunSingleCommand) Execute(c *cli.Context) {
log
.
Println
(
"Starting runner for"
,
r
.
URL
,
"with token"
,
r
.
ShortDescription
(),
"..."
)
log
.
Println
(
"Starting runner for"
,
r
.
URL
,
"with token"
,
r
.
ShortDescription
(),
"..."
)
r
.
finished
=
false
r
.
finished
=
abool
.
New
()
abortSignal
:=
make
(
chan
os
.
Signal
)
abortSignal
:=
make
(
chan
os
.
Signal
)
doneSignal
:=
make
(
chan
int
,
1
)
doneSignal
:=
make
(
chan
int
,
1
)
r
.
runForever
=
r
.
MaxBuilds
==
0
r
.
runForever
=
r
.
MaxBuilds
==
0
go
waitForInterrupts
(
&
r
.
finished
,
abortSignal
,
doneSignal
)
go
waitForInterrupts
(
r
.
finished
,
abortSignal
,
doneSignal
)
r
.
lastBuild
=
time
.
Now
()
r
.
lastBuild
=
time
.
Now
()
for
!
r
.
finished
{
for
!
r
.
finished
.
IsSet
()
{
data
,
err
:=
executorProvider
.
Acquire
(
&
r
.
RunnerConfig
)
data
,
err
:=
executorProvider
.
Acquire
(
&
r
.
RunnerConfig
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Warningln
(
"Executor update:"
,
err
)
log
.
Warningln
(
"Executor update:"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment