Skip to content

Commit cac032f

Browse files
authored
[QT-329] cli: fix a bug where we could replay the wrong events (#71)
cli: Handle cases where we receive events out of order and replay the wrong event
1 parent 24df8f3 commit cac032f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/client/operation_stream.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func (c *Connection) streamResponses(
9292
eventC := make(chan *pb.Operation_Event)
9393
errC := make(chan error)
9494
ticker := time.NewTicker(5 * time.Second)
95-
var mostRecentEventPublishedAt time.Time
9695
var lastEvent *pb.Operation_Event
9796

9897
// Start the operation event stream poller
@@ -139,11 +138,13 @@ func (c *Connection) streamResponses(
139138
"operation_id", ref.GetId(),
140139
"published_at", event.GetPublishedAt(),
141140
)
142-
lastEvent = event
143141

144-
if mostRecent := event.GetPublishedAt().AsTime(); mostRecent.After(mostRecentEventPublishedAt) {
145-
// Only publish events that are newer than our last event
146-
mostRecentEventPublishedAt = mostRecent
142+
if lastEvent == nil || event.GetPublishedAt().AsTime().After(lastEvent.GetPublishedAt().AsTime()) {
143+
// Because our events are not guaranteed to be in order
144+
// we'll only update our last event if it was published
145+
// more recently. This ensures that when we "replay"
146+
// events while waiting we always show the most recent.
147+
lastEvent = event
147148
ui.ShowOperationEvent(event)
148149
ticker.Reset(5 * time.Second)
149150
}

0 commit comments

Comments
 (0)