From ddc7d0e1001d4301ed3633e10afd2c5cd22157de Mon Sep 17 00:00:00 2001 From: mudler Date: Tue, 25 Mar 2025 18:48:15 +0100 Subject: [PATCH] handle lock inside goroutine Signed-off-by: mudler --- services/connectors/slack.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/services/connectors/slack.go b/services/connectors/slack.go index ab6cb2d..2e4e1ea 100644 --- a/services/connectors/slack.go +++ b/services/connectors/slack.go @@ -196,28 +196,28 @@ func (t *Slack) handleChannelMessage( currentConv := t.conversationTracker.GetConversation(t.channelID) - // Lock the conversation mutex to update the conversation history - t.processing.Lock() - - // If we are already processing something, stop the current action - if t.processingMessage { - a.StopAction() - } else { - t.processingMessage = true - } - t.processing.Unlock() - - // Defer to reset the processing flag - defer func() { - t.processing.Lock() - t.processingMessage = false - t.processing.Unlock() - }() - message := replaceUserIDsWithNamesInMessage(api, cleanUpUsernameFromMessage(ev.Text, b)) go func() { + // Lock the conversation mutex to update the conversation history + t.processing.Lock() + + // If we are already processing something, stop the current action + if t.processingMessage { + a.StopAction() + } else { + t.processingMessage = true + } + t.processing.Unlock() + + // Defer to reset the processing flag + defer func() { + t.processing.Lock() + t.processingMessage = false + t.processing.Unlock() + }() + imageBytes := new(bytes.Buffer) mimeType := "image/jpeg"