From 2f3caba65e79900f93e3f0039949df5ef4d2e1d4 Mon Sep 17 00:00:00 2001 From: AKP Date: Sat, 8 Apr 2023 16:53:45 +0100 Subject: Fix potential race condition Due to a use of `RLock` in place of `Lock` in test email status reporting code, a race condition could arise when more than one user is running a test email. Signed-off-by: AKP --- CHANGELOG.md | 3 +++ walrss/internal/http/testEmail.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f6ea0c..d31922c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Fixed +* Remove potential race condition caused by using `RLock` instead of `Lock` + ## 0.3.6 - 2023-02-25 ### Changed * Updated Go build version diff --git a/walrss/internal/http/testEmail.go b/walrss/internal/http/testEmail.go index 5070cbf..86c3e60 100644 --- a/walrss/internal/http/testEmail.go +++ b/walrss/internal/http/testEmail.go @@ -66,11 +66,14 @@ func (s *Server) testEmailStatus(ctx *fiber.Ctx) error { testEmailStatesLock.RLock() var content string if end { + testEmailStatesLock.RUnlock() + testEmailStatesLock.Lock() delete(testEmailStates, currentUserID) + testEmailStatesLock.Unlock() } else { content = testEmailStates[currentUserID] + testEmailStatesLock.RUnlock() } - defer testEmailStatesLock.RUnlock() if end { ctx.Set("HX-Refresh", "true") -- cgit v1.2.3-70-g09d2