You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix concurrency errors, memory leaks, and add rate limiting (#1)
* Fix concurrency errors, memory leaks, and add rate limiting
- Added mutexes (sync.RWMutex/sync.Mutex) to protect global shared state (zone, measures, conditions, themes, current weather client).
- Fixed a memory leak in the rate limiter by adding a background cleanup goroutine for inactive IPs.
- Improved DoS protection by adding a global rate limiter (100 req/s) in addition to the per-IP limiter.
- Fixed an initialization bug in `loadConditions` using `sync.Once` and properly storing the error for subsequent calls.
- Resolved a shadowing bug in `getDataPoints` and corrected its error message.
- Configured SQLite with `MaxOpenConns(1)` to prevent database locking issues.
- Ensured thread-safe access to templates and themes in `getServeMux` using `sync.Once`.
Co-authored-by: birabittoh <26506860+birabittoh@users.noreply.github.com>
* Fix concurrency errors, memory leaks, and add IP-based rate limiting with LRU cache
- Implemented IP-based rate limiting using `github.com/hashicorp/golang-lru/v2` to bound memory usage and prevent leaks.
- Added a global rate limiter for overall server protection.
- Protected global shared state (zone, measures, conditions, themes, templates, current weather client) with mutexes and `sync.Once`.
- Configured SQLite with `MaxOpenConns(1)` to avoid locking issues.
- Fixed logical bugs in `getDataPoints` and `loadConditions`.
- Updated `go.mod` and `go.sum` with the new LRU cache dependency.
Co-authored-by: birabittoh <26506860+birabittoh@users.noreply.github.com>
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: birabittoh <26506860+birabittoh@users.noreply.github.com>
0 commit comments