Skip to content

Commit

Permalink
Further improve requestedSeqNum check
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Dec 21, 2023
1 parent 11d76f6 commit 4b816bc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions wsbroadcastserver/clientconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (cc *ClientConnection) Remove() {

func (cc *ClientConnection) writeBacklog(ctx context.Context, segment backlog.BacklogSegment) error {
var prevSegment backlog.BacklogSegment
isFirstSegment := true
for !backlog.IsBacklogSegmentNil(segment) {
// must get the next segment before the messages to be sent are
// retrieved ensures another segment is not added in between calls.
Expand All @@ -132,13 +133,14 @@ func (cc *ClientConnection) writeBacklog(ctx context.Context, segment backlog.Ba
}

msgs := prevSegment.Messages()
if prevSegment.Contains(uint64(cc.requestedSeqNum)) {
if isFirstSegment && prevSegment.Contains(uint64(cc.requestedSeqNum)) {
requestedIdx := int(cc.requestedSeqNum) - int(prevSegment.Start())
// This might be false if messages were added after we fetched the segment's messages
if len(msgs) > requestedIdx {
if len(msgs) >= requestedIdx {
msgs = msgs[requestedIdx:]
}
}
isFirstSegment = false
bm := &m.BroadcastMessage{
Version: m.V1,
Messages: msgs,
Expand Down

0 comments on commit 4b816bc

Please sign in to comment.