Skip to content

Commit

Permalink
libgv/channel: break correct loop on reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 26, 2024
1 parent 6db9d4e commit f665030
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/libgv/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (c *Client) RunRealtimeChannel(ctx context.Context) error {
c.dispatchEvent(ctx, &RealtimeConnected{})
}
reader := utf16chunk.NewReader(resp.Body)
ReadLoop:
for {
var chunk []byte
chunk, err = reader.ReadChunk()
Expand Down Expand Up @@ -182,14 +183,15 @@ func (c *Client) RunRealtimeChannel(ctx context.Context) error {
return fmt.Errorf("failed to parse entry #%d: %w", i+1, err)
}
if len(parsed.GetDataWrapper()) == 1 && parsed.GetDataWrapper()[0].GetAltData().GetReconnect() {
_ = resp.Body.Close()
log.Debug().Msg("Got event that probably means we need to reconnect")
gSessionID, channel, err = c.SubscribeRealtimeChannel(ctx)
if err != nil {
return fmt.Errorf("failed to re-subscribe after timeout: %w", err)
}
lastResubscribe = time.Now()
ackID = 0
break
break ReadLoop
}
ackID = parsed.ArrayID
c.dispatchEvent(ctx, &RealtimeEvent{WebChannelEvent: &parsed})
Expand Down

0 comments on commit f665030

Please sign in to comment.