Skip to content

Commit fc53f5f

Browse files
committed
docker: sync access to exit result within a handle
1 parent ace09b3 commit fc53f5f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

drivers/docker/driver.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ type Driver struct {
8383
// coordinator is what tracks multiple image pulls against the same docker image
8484
coordinator *dockerCoordinator
8585

86-
// logger will log to the plugin output which is usually an 'executor.out'
87-
// file located in the root of the TaskDir
86+
// logger will log to the Nomad agent
8887
logger hclog.Logger
8988
}
9089

@@ -990,7 +989,7 @@ func (d *Driver) handleWait(ctx context.Context, ch chan *drivers.ExitResult, h
990989
defer close(ch)
991990
select {
992991
case <-h.waitCh:
993-
ch <- h.exitResult
992+
ch <- h.ExitResult()
994993
case <-ctx.Done():
995994
ch <- &drivers.ExitResult{
996995
Err: ctx.Err(),
@@ -1080,7 +1079,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
10801079
"container_id": container.ID,
10811080
},
10821081
NetworkOverride: h.net,
1083-
ExitResult: h.exitResult,
1082+
ExitResult: h.ExitResult(),
10841083
}
10851084

10861085
status.State = drivers.TaskStateUnknown

drivers/docker/handle.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ type taskHandle struct {
3838
net *structs.DriverNetwork
3939
imageID string
4040

41-
exitResult *drivers.ExitResult
41+
exitResult *drivers.ExitResult
42+
exitResultLock sync.Mutex
43+
}
44+
45+
func (h *taskHandle) ExitResult() *drivers.ExitResult {
46+
h.exitResultLock.Lock()
47+
defer h.exitResultLock.Unlock()
48+
return h.exitResult.Copy()
4249
}
4350

4451
type taskHandleState struct {
@@ -202,12 +209,14 @@ func (h *taskHandle) run() {
202209
}
203210

204211
// Set the result
212+
h.exitResultLock.Lock()
205213
h.exitResult = &drivers.ExitResult{
206214
ExitCode: exitCode,
207215
Signal: 0,
208216
OOMKilled: oom,
209217
Err: werr,
210218
}
219+
h.exitResultLock.Unlock()
211220
close(h.waitCh)
212221
}
213222

plugins/drivers/driver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ func (r *ExitResult) Successful() bool {
249249
return r.ExitCode == 0 && r.Signal == 0 && r.Err == nil
250250
}
251251

252+
func (r *ExitResult) Copy() *ExitResult {
253+
res := new(ExitResult)
254+
*res = *r
255+
return res
256+
}
257+
252258
type TaskStatus struct {
253259
ID string
254260
Name string

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy