diff options
| author | AKP <tom@tdpain.net> | 2023-04-08 16:53:45 +0100 |
|---|---|---|
| committer | AKP <tom@tdpain.net> | 2023-04-08 16:53:45 +0100 |
| commit | 2f3caba65e79900f93e3f0039949df5ef4d2e1d4 (patch) | |
| tree | 503685e1cb1844344ed74e659b57b8ffca9105b4 | |
| parent | 78233315228adb1cb2a8b666d0ca684f57ac0e13 (diff) | |
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 <tom@tdpain.net>
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | walrss/internal/http/testEmail.go | 5 |
2 files changed, 7 insertions, 1 deletions
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") |
