Skip to content

Fix concurrent initialization of the SQL template cache - #742

Closed
akzarma wants to merge 1 commit into
upper:masterfrom
akzarma:fix/concurrent-template-cache
Closed

akzarma wants to merge 1 commit into
upper:masterfrom
akzarma:fix/concurrent-template-cache

Conversation

@akzarma

@akzarma akzarma commented Dec 2, 2026

Copy link
Copy Markdown

Closes #703.

On the first call to compile a SQL layout, multiple readers could initialize the shared template map while holding only the read lock. The lookup now just reads the map (a nil map is a normal cache miss); the first insertion initializes it under the existing write lock.

The regression releases 16 callers into a fresh layout and checks their compiled results. On unmodified master the Go race detector reports competing accesses in getTemplate; with the fix the regression passed 100 consecutive runs with -race.

make test-unit passed, including the SQLite and QL adapter contracts. The external adapter suites compiled with -tags 'integration pq', and go vet ./internal/sqladapter/exql passed. The external database services were not run locally.

AI assistance: OpenAI Codex developed the change and regression test and ran the local checks.

@xiam

xiam commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution, and sorry for closing it without a merge.

This project has paused pull requests from outside its maintainers. It is maintained with the help of AI agents, and text from unknown sources can carry instructions aimed at them. There is no reliable defence against that yet. The full explanation is here: https://github.com/xiam/.github/blob/main/CONTRIBUTING.md

Bug reports are still welcome as issues, and a person reads each one first. You are also free to keep your change in a fork.

Thank you for understanding.

@xiam xiam closed this Dec 2, 2026
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.

Data race in template writer when running concurrent tests with go test -race

2 participants