Skip to content

Commit c6ee013

Browse files
committed
Fix deadlock in Go SDK harness data/state channel managers
1 parent 33ad247 commit c6ee013

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

sdks/go/pkg/beam/core/runtime/harness/datamgr.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ func (m *DataChannelManager) Open(ctx context.Context, port exec.Port) (*DataCha
136136
default:
137137
log.Warnf(ctx, "forcing DataChannel[%v] reconnection on port %v due to %v", id, port, err)
138138
}
139-
m.mu.Lock()
140-
delete(m.ports, port.URL)
141-
m.mu.Unlock()
139+
go func() {
140+
m.mu.Lock()
141+
defer m.mu.Unlock()
142+
if curr, ok := m.ports[port.URL]; ok && curr == ch {
143+
delete(m.ports, port.URL)
144+
}
145+
}()
142146
}
143147
m.ports[port.URL] = ch
144148
return ch, nil

sdks/go/pkg/beam/core/runtime/harness/statemgr.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,13 @@ func (m *StateChannelManager) Open(ctx context.Context, port exec.Port) (*StateC
619619
default:
620620
log.Warnf(ctx, "forcing StateChannel[%v] reconnection on port %v due to %v", id, port, err)
621621
}
622-
m.mu.Lock()
623-
delete(m.ports, port.URL)
624-
m.mu.Unlock()
622+
go func() {
623+
m.mu.Lock()
624+
defer m.mu.Unlock()
625+
if curr, ok := m.ports[port.URL]; ok && curr == ch {
626+
delete(m.ports, port.URL)
627+
}
628+
}()
625629
}
626630
m.ports[port.URL] = ch
627631
return ch, nil

0 commit comments

Comments
 (0)