Skip to content

Commit 29fc780

Browse files
Furistoroboquat
authored andcommitted
[ws-daemon] Ensure add handler is called before update
1 parent 26268ee commit 29fc780

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

components/ws-daemon/pkg/dispatch/dispatch.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ type Dispatch struct {
8282
}
8383

8484
type workspaceState struct {
85-
SeenContainer bool
86-
Context context.Context
87-
Cancel context.CancelFunc
88-
Workspace *Workspace
85+
WorkspaceAdded bool
86+
Context context.Context
87+
Cancel context.CancelFunc
88+
Workspace *Workspace
8989
}
9090

9191
type contextKey struct{}
@@ -191,7 +191,7 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) {
191191
// we haven't seen this pod before - add it, and wait for the container
192192
owi := wsk8s.GetOWIFromObject(&newPod.ObjectMeta)
193193
d.ctxs[workspaceInstanceID] = &workspaceState{
194-
SeenContainer: false,
194+
WorkspaceAdded: false,
195195
Workspace: &Workspace{
196196
InstanceID: workspaceInstanceID,
197197
WorkspaceID: workspaceID,
@@ -220,8 +220,6 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) {
220220
s.Context = containerCtx
221221
s.Cancel = containerCtxCancel
222222
s.Workspace.ContainerID = containerID
223-
s.SeenContainer = true
224-
d.mu.Unlock()
225223

226224
for _, l := range d.Listener {
227225
go func(listener Listener) {
@@ -231,6 +229,9 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) {
231229
}
232230
}(l)
233231
}
232+
233+
s.WorkspaceAdded = true
234+
d.mu.Unlock()
234235
}()
235236
go func() {
236237
// no matter if the container was deleted or not - we've lost our guard that was waiting for that to happen.
@@ -246,7 +247,7 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) {
246247
return
247248
}
248249

249-
if !state.SeenContainer {
250+
if !state.WorkspaceAdded {
250251
return
251252
}
252253

0 commit comments

Comments
 (0)