enhancement: staticCookieJar is not thread-safe #20

Closed
opened 2026-02-14 16:07:12 +00:00 by Claude · 2 comments
Collaborator

Parent: #3

Description

staticCookieJar in cookies_txt.go is a slice type with Set(), Delete(), Get(), and GetAll() methods that read and mutate the slice without synchronization.

If a CookieJar is shared between goroutines (e.g., multiple pages in the same browser context), concurrent Set() + Get() calls would cause data races.

Current risk

Low — the current codebase doesn't appear to use the cookie jar concurrently. But as a public interface (CookieJar), callers might use it in concurrent contexts.

Fix

Add a sync.RWMutex to staticCookieJar, or document that it's not safe for concurrent use. A wrapper type SafeCookieJar could be provided for thread-safe use.

**Parent:** #3 ## Description `staticCookieJar` in `cookies_txt.go` is a slice type with `Set()`, `Delete()`, `Get()`, and `GetAll()` methods that read and mutate the slice without synchronization. If a `CookieJar` is shared between goroutines (e.g., multiple pages in the same browser context), concurrent `Set()` + `Get()` calls would cause data races. ## Current risk Low — the current codebase doesn't appear to use the cookie jar concurrently. But as a public interface (`CookieJar`), callers might use it in concurrent contexts. ## Fix Add a `sync.RWMutex` to `staticCookieJar`, or document that it's not safe for concurrent use. A wrapper type `SafeCookieJar` could be provided for thread-safe use.
Claude added the enhancementpriority/low labels 2026-02-14 16:07:37 +00:00
Author
Collaborator

Starting work on this. Will wrap staticCookieJar in a struct with sync.RWMutex for thread safety.

Starting work on this. Will wrap `staticCookieJar` in a struct with `sync.RWMutex` for thread safety.
Author
Collaborator

Work finished — staticCookieJar is now a struct with sync.RWMutex. All reads use RLock, all writes use Lock. Merged in PR #42.

Work finished — `staticCookieJar` is now a struct with `sync.RWMutex`. All reads use `RLock`, all writes use `Lock`. Merged in PR #42.
Sign in to join this conversation.