Files
aptly/database/etcddb/database.go
T
Nick Bozhenko 1693863499 Fix S3 concurrent map writes causing pod crashes
PROBLEM:
- Pod crashes with "fatal error: concurrent map writes" during S3 publications
- Root cause: pathCache map in PublishedStorage accessed without synchronization
- Occurs during concurrent LinkFromPool operations in S3 publishing

SOLUTION:
- Add sync.RWMutex to PublishedStorage struct for thread-safe map access
- Implement double-check locking pattern for cache initialization
- Protect all map operations (read/write/delete) with appropriate locks

CHANGES:
- s3/public.go: Add pathCacheMutex field and protect all map operations
  * Cache initialization with double-check locking in LinkFromPool
  * Read operations protected with RLock/RUnlock
  * Write operations protected with Lock/Unlock
  * Delete operations in Remove() and RemoveDirs() protected

IMPACT:
- Eliminates concurrent map writes panic
- Prevents pod crashes during S3 publications
- Maintains performance with minimal synchronization overhead
- Uses read-write locks allowing concurrent reads while serializing writes
2025-07-15 22:46:37 -04:00

33 lines
674 B
Go

package etcddb
import (
"context"
"time"
"github.com/aptly-dev/aptly/database"
clientv3 "go.etcd.io/etcd/client/v3"
)
var Ctx = context.TODO()
func internalOpen(url string) (cli *clientv3.Client, err error) {
cfg := clientv3.Config{
Endpoints: []string{url},
DialTimeout: 30 * time.Second,
MaxCallSendMsgSize: 2147483647, // (2048 * 1024 * 1024) - 1
MaxCallRecvMsgSize: 2147483647,
DialKeepAliveTimeout: 7200 * time.Second,
}
cli, err = clientv3.New(cfg)
return
}
func NewDB(url string) (database.Storage, error) {
cli, err := internalOpen(url)
if err != nil {
return nil, err
}
return &EtcDStorage{url, cli, ""}, nil
}