Commit Graph

4 Commits

Author SHA1 Message Date
Nathan Wallace
5ee33414b7 Fix concurrent access to sessions map in Close() closes #4793 (#4836)
* Add tests demonstrating bug #4793: Close() sets sessions=nil without mutex

These tests demonstrate the race condition where Close() sets c.sessions
to nil without holding the mutex, while AcquireSession() tries to access
the map with the mutex held.

Running with -race detects the data race and the test panics with
"assignment to entry in nil map".

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix #4793: Protect sessions map access with mutex in Close()

Acquire sessionsMutex before setting sessions to nil in Close() to prevent
data race with AcquireSession(). Also add nil check in AcquireSession() to
handle the case where Close() has been called.

This prevents the panic "assignment to entry in nil map" when Close() and
AcquireSession() are called concurrently.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-15 11:29:57 -05:00
Nathan Wallace
11ce53cfc4 Race condition on disableTiming field closes #4808 (rebased) (#4890)
* Add test for #4808: Race condition on disableTiming field

Add test that verifies disableTiming field uses atomic.Bool instead of
plain bool to prevent race conditions.

The test checks that:
- disableTiming is declared as atomic.Bool
- shouldFetchTiming() uses atomic Load()
- getQueryTiming() uses atomic Store() operations
- Direct assignments that cause races are not present

This test will fail until the implementation is fixed.

* Fix #4808: Use atomic.Bool for disableTiming to prevent race condition
2025-11-15 11:05:25 -05:00
Nathan Wallace
2e5f3fda97 Add comprehensive passing tests from bug hunting initiative (#4864) 2025-11-13 09:26:46 +08:00
Nathan Wallace
99fd81ccf6 Fix memory leak in DatabaseSession management (issue #3737) (#4742) 2025-11-11 18:35:16 +08:00