Skip to content

Commit f366508

Browse files
dharmabclaude
andauthored
Fix sendUpdates holding RLock while blocking on unbuffered channel (#682)
## Summary - Extract `collectUpdates()` to build a `[]sim.Updated` snapshot under the read lock, then release it before sending on the channel - Prevents write-lock starvation in `applyObjectUpdate()` and `handleTimeFrame()` when the radar consumer is slow Closes #660 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d2c92f1 commit f366508

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

pkg/telemetry/streamer.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,20 @@ func (c *streamingClient) Time() time.Time {
119119
}
120120

121121
func (c *streamingClient) sendUpdates(updates chan<- sim.Updated) {
122+
snapshot := c.collectUpdates()
123+
for _, u := range snapshot {
124+
updates <- u
125+
}
126+
}
127+
128+
func (c *streamingClient) collectUpdates() []sim.Updated {
122129
c.lock.RLock()
123130
defer c.lock.RUnlock()
124131

132+
result := make([]sim.Updated, 0, len(c.state))
125133
for _, object := range c.state {
126134
logger := log.With().Uint64("id", object.ID).Logger()
127-
// Only send updates for aircraft.
135+
// Only collect updates for aircraft.
128136
taglist, err := object.GetTypes()
129137
if err != nil {
130138
logger.Error().Err(err).Msg("error getting object types")
@@ -179,16 +187,17 @@ func (c *streamingClient) sendUpdates(updates chan<- sim.Updated) {
179187
frame.AGL = &agl
180188
}
181189

182-
updates <- sim.Updated{
190+
result = append(result, sim.Updated{
183191
Labels: trackfiles.Labels{
184192
ID: object.ID,
185193
Name: callsign,
186194
Coalition: coalition,
187195
ACMIName: name,
188196
},
189197
Frame: frame,
190-
}
198+
})
191199
}
200+
return result
192201
}
193202

194203
func (c *streamingClient) handleLines(ctx context.Context, reader *bufio.Reader) error {

0 commit comments

Comments
 (0)