Skip to content

Conversation

@justonedev1
Copy link
Collaborator

This patch fixes the panic: runtime error: invalid memory address or nil pointer dereference error triggering in tests. It was caused by the racecondition between Run() and Stop(). Run is blocking so it has to be called in goroutine (that is on purpose so we can handle errors in core) so sometimes Stop() is called to quickly before Run is done, so you could call ListenAndServe on an empty object.
Usage of atomic pointer is not strictly necessary for the fix of mentioned problem. But it assures that no goroutine will be stuck if we change global server too quickly. Usage of the atomic pointer doesn't cause any performance penalty as it just holds the global server and nothing more.

This bug couldn't influence production as we didn't call Run() and immediately Stop().

@justonedev1 justonedev1 requested a review from knopers8 as a code owner August 21, 2025 11:03
@justonedev1 justonedev1 force-pushed the fix_tests_racecondition branch from 62102fe to 37f8aa3 Compare August 21, 2025 11:05
@justonedev1 justonedev1 requested a review from knopers8 August 26, 2025 13:55

func Stop() {
if !IsRunning() {
srv := server.Swap(nil)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please apply the same renaming in Stop

@justonedev1 justonedev1 force-pushed the fix_tests_racecondition branch from eadca54 to 3494a46 Compare September 2, 2025 07:55
@justonedev1 justonedev1 requested a review from knopers8 September 2, 2025 07:55
@knopers8 knopers8 merged commit 01b9d2e into master Sep 3, 2025
4 checks passed
@knopers8 knopers8 deleted the fix_tests_racecondition branch September 3, 2025 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants