Skip to content

devops: concurrent canvas creation and lookup race on CanvasInfo #961

Description

@dajiaohuang

Description

CreateCanvas reads the graph container under s.mu but assigns c.CanvasInfo after releasing the mutex. GetCanvas reads the same pointer while holding s.mu.RLock, so the write is not synchronized with readers or with another concurrent CreateCanvas call.

Reproduction

On current main (6752ff8da9b1ea85c8e91b27b0a64fef099f22f9), a test that repeatedly calls CreateCanvas and GetCanvas concurrently reports read/write and write/write races:

go test -race -gcflags='all=-N -l' ./internal/service -run '^TestAuditCreateCanvasRace$' -count=1
WARNING: DATA RACE
Read ... container.go:233 / container.go:237
Previous write ... container.go:223

This was reproduced with Linux and Go 1.25.6, matching the repository CI Go version.

Expected behavior

All access to GraphContainer.CanvasInfo should be protected by the container service mutex.

Suggested fix

Acquire s.mu for the cache assignment after building the schema, and add a concurrent regression test that passes under the race detector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions