diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/userstream.go b/src/github.com/matrix-org/dendrite/syncapi/sync/userstream.go index a05b9e8fd..6dc1821c2 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/userstream.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/userstream.go @@ -77,7 +77,7 @@ func (s *UserStream) Wait(ctx context.Context, waitAtPos types.StreamPosition) < // Icky but efficient way of filtering out the given channel for idx, ch := range s.waitingChannels { if posChannel == ch { - lastIdx := len(s.waitingChannels) + lastIdx := len(s.waitingChannels) - 1 s.waitingChannels[idx] = s.waitingChannels[lastIdx] s.waitingChannels[lastIdx] = nil // Ensure that the channel gets GCed s.waitingChannels = s.waitingChannels[:lastIdx]