Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 0b67332

Browse files
committed
Merge pull request #317 from gao-feng/wait
wait cleanup job finished in stop pod
2 parents dc966a8 + 4c28c4d commit 0b67332

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

daemon/pod.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Pod struct {
3838
ctnStartInfo []*hypervisor.ContainerInfo
3939
volumes map[string]*hypervisor.VolumeInfo
4040
ttyList map[string]*hypervisor.TtyIO
41+
wg *sync.WaitGroup
4142

4243
transiting chan bool
4344
sync.RWMutex
@@ -241,6 +242,7 @@ func NewPod(podSpec *apitypes.UserPod, id string, data interface{}) (*Pod, error
241242
ttyList: make(map[string]*hypervisor.TtyIO),
242243
volumes: make(map[string]*hypervisor.VolumeInfo),
243244
transiting: make(chan bool, 1),
245+
wg: new(sync.WaitGroup),
244246
}
245247

246248
// fill one element in transit chan, only one parallel op is allowed
@@ -1190,6 +1192,7 @@ func (p *Pod) Start(daemon *Daemon, vmId string, lazy bool, streams []*hyperviso
11901192
return vmResponse, err
11911193
}
11921194

1195+
p.wg.Add(1)
11931196
err = daemon.db.UpdateVM(p.vm.Id, vmResponse.Data.([]byte))
11941197
if err != nil {
11951198
glog.Error(err.Error())

daemon/stop.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ func (daemon *Daemon) PodStopped(podId string) {
1616
return
1717
}
1818

19+
defer pod.wg.Done()
20+
1921
pod.Lock()
2022
defer pod.Unlock()
2123

@@ -81,18 +83,20 @@ func (daemon *Daemon) StopPodWithinLock(pod *Pod) (int, string, error) {
8183
}
8284

8385
pod.Lock()
84-
defer pod.Unlock()
8586

8687
if pod.vm == nil {
88+
pod.Unlock()
8789
return types.E_VM_SHUTDOWN, "", nil
8890
}
8991

9092
if pod.status.Status != types.S_POD_RUNNING {
93+
pod.Unlock()
9194
glog.Errorf("Pod %s is not in running state, cannot be stopped", pod.Id)
9295
return -1, "", fmt.Errorf("Pod %s is not in running state, cannot be stopped", pod.Id)
9396
}
9497

9598
vmResponse := pod.vm.StopPod(pod.status)
96-
99+
pod.Unlock()
100+
pod.wg.Wait()
97101
return vmResponse.Code, vmResponse.Cause, nil
98102
}

0 commit comments

Comments
 (0)