Avoid ServeApi race condition
| ... | ... |
@@ -32,7 +32,7 @@ import ( |
| 32 | 32 |
) |
| 33 | 33 |
|
| 34 | 34 |
var ( |
| 35 |
- activationLock chan struct{}
|
|
| 35 |
+ activationLock chan struct{} = make(chan struct{})
|
|
| 36 | 36 |
) |
| 37 | 37 |
|
| 38 | 38 |
type HttpServer struct {
|
| ... | ... |
@@ -1445,7 +1445,6 @@ func ServeApi(job *engine.Job) error {
|
| 1445 | 1445 |
protoAddrs = job.Args |
| 1446 | 1446 |
chErrors = make(chan error, len(protoAddrs)) |
| 1447 | 1447 |
) |
| 1448 |
- activationLock = make(chan struct{})
|
|
| 1449 | 1448 |
|
| 1450 | 1449 |
for _, protoAddr := range protoAddrs {
|
| 1451 | 1450 |
protoAddrParts := strings.SplitN(protoAddr, "://", 2) |
| ... | ... |
@@ -82,7 +82,9 @@ func AcceptConnections(job *engine.Job) error {
|
| 82 | 82 |
// Tell the init daemon we are accepting requests |
| 83 | 83 |
go systemd.SdNotify("READY=1")
|
| 84 | 84 |
// close the lock so the listeners start accepting connections |
| 85 |
- if activationLock != nil {
|
|
| 85 |
+ select {
|
|
| 86 |
+ case <-activationLock: |
|
| 87 |
+ default: |
|
| 86 | 88 |
close(activationLock) |
| 87 | 89 |
} |
| 88 | 90 |
return nil |