Skip to content

Commit

Permalink
Fix broadcastSegment Contains and its usage
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Dec 21, 2023
1 parent ae54e08 commit 11d76f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion broadcaster/backlog/backlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (s *backlogSegment) Contains(i uint64) bool {
s.messagesLock.RLock()
defer s.messagesLock.RUnlock()
start := s.start()
if i < start || i > s.end() {
if i < start || i > s.end() || len(s.messages) == 0 {
return false
}

Expand Down
5 changes: 4 additions & 1 deletion wsbroadcastserver/clientconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ func (cc *ClientConnection) writeBacklog(ctx context.Context, segment backlog.Ba
msgs := prevSegment.Messages()
if prevSegment.Contains(uint64(cc.requestedSeqNum)) {
requestedIdx := int(cc.requestedSeqNum) - int(prevSegment.Start())
msgs = msgs[requestedIdx:]
// This might be false if messages were added after we fetched the segment's messages
if len(msgs) > requestedIdx {
msgs = msgs[requestedIdx:]
}
}
bm := &m.BroadcastMessage{
Version: m.V1,
Expand Down

0 comments on commit 11d76f6

Please sign in to comment.