Skip to content

Fix crash during /reload from nil connection race condition#971

Merged
burningalchemist merged 1 commit intoburningalchemist:masterfrom
utafrali:fix/issue-970-reload-causes-sql-export-to-crash
Apr 10, 2026
Merged

Fix crash during /reload from nil connection race condition#971
burningalchemist merged 1 commit intoburningalchemist:masterfrom
utafrali:fix/issue-970-reload-causes-sql-export-to-crash

Conversation

@utafrali
Copy link
Copy Markdown
Contributor

Fixes #970

Collectors were capturing t.conn directly in the goroutine closure, so if reload cleared the connection before the goroutine ran, it'd panic. Grabbing the connection value up front before spawning the goroutines avoids the race. Added a nil check in query.run() as a defensive measure too.

@burningalchemist
Copy link
Copy Markdown
Owner

Hey @utafrali thank you for your contribution! 👍 Let me briefly review the PR, but overall looks good to me. 👏

@burningalchemist
Copy link
Copy Markdown
Owner

I think there are several extra weak spots to address (e.g. we may want to introduce mutex over t.conn), but this can be improved separately. 👍

@burningalchemist burningalchemist merged commit 8226aed into burningalchemist:master Apr 10, 2026
4 checks passed
@burningalchemist
Copy link
Copy Markdown
Owner

Hey @utafrali, I tested your fix, and still managed to reproduce the bug (hitting reloads and scraping /metrics at the same time for 1 million times seems a good test 😆).

I added mutexes as I wanted earlier in #972, and it seems to survive the aggressive reloading/scraping. Just keeping you in the loop. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/Reload causes sql_export to crash

2 participants