Skip to content

Commit 94b8f94

Browse files
author
zc
authored
resolve race condition during creation (#219)
1 parent ec48556 commit 94b8f94

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

cluster/calcium/create.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,15 @@ func (c *Calcium) doCreateAndStartContainer(
225225
// Copy data to container
226226
if len(opts.Data) > 0 {
227227
for dst, src := range opts.Data {
228-
if _, err = src.Seek(0, io.SeekStart); err != nil {
229-
return err
228+
mutexSend := func() error {
229+
opts.Mux.Lock()
230+
defer opts.Mux.Unlock()
231+
if _, err = src.Seek(0, io.SeekStart); err != nil {
232+
return err
233+
}
234+
return c.doSendFileToContainer(ctx, node.Engine, container.ID, dst, src, true, true)
230235
}
231-
if err = c.doSendFileToContainer(ctx, node.Engine, container.ID, dst, src, true, true); err != nil {
236+
if err = mutexSend(); err != nil {
232237
return err
233238
}
234239
}

types/options.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package types
22

3-
import "bytes"
3+
import (
4+
"bytes"
5+
"sync"
6+
)
47

58
// DeployOptions is options for deploying
69
type DeployOptions struct {
@@ -35,6 +38,8 @@ type DeployOptions struct {
3538
AfterCreate []string // AfterCreate support run cmds after create
3639
RawArgs []byte // RawArgs for raw args processing
3740
Lambda bool // indicate is lambda container or not
41+
42+
Mux sync.Mutex // used for concurrent send during creation
3843
}
3944

4045
// Normalize keeps deploy options consistant

0 commit comments

Comments
 (0)