diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index fabd3ac..b0da6e1 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -814,7 +814,7 @@ func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern stri if err != nil { log.Errorf("could not fetch channel count for conversation %d:%d: %s", conversation.ID, 0, err) } - if maxCount > count { + if count > maxCount { maxCount = count } conversationCount[conversation.ID] = count @@ -850,6 +850,9 @@ func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern stri // Note: This should note be used to index a list as the ID is not expected to be tied to absolute position // in the table (e.g. deleted messages, expired messages, etc.) func (cp *cwtchPeer) SearchConversations(pattern string) string { + // we need this lock here to prevent weirdness happening when reassigning cp.cancelSearchContext + cp.mutex.Lock() + defer cp.mutex.Unlock() if cp.cancelSearchContext != nil { cp.cancelSearchContext() // Cancel any current searches... }