소스 검색

Fix race condition crash on concurrent accesses to the same file

https://github.com/dutchcoders/transfer.sh/issues/380
at-2021
JustAnotherArchivist 2 년 전
부모
커밋
e4132f625b
2개의 변경된 파일8개의 추가작업 그리고 13개의 파일을 삭제
  1. +6
    -11
      server/handlers.go
  2. +2
    -2
      server/server.go

+ 6
- 11
server/handlers.go 파일 보기

@@ -625,23 +625,18 @@ func (metadata Metadata) remainingLimitHeaderValues() (remainingDownloads, remai
return remainingDownloads, remainingDays
}

func (s *Server) Lock(token, filename string) error {
func (s *Server) Lock(token, filename string) {
key := path.Join(token, filename)

if _, ok := s.locks[key]; !ok {
s.locks[key] = &sync.Mutex{}
}

s.locks[key].Lock()

return nil
lock, _ := s.locks.LoadOrStore(key, &sync.Mutex{})
lock.(*sync.Mutex).Lock()
}

func (s *Server) Unlock(token, filename string) error {
func (s *Server) Unlock(token, filename string) {
key := path.Join(token, filename)
s.locks[key].Unlock()

return nil
lock, _ := s.locks.LoadOrStore(key, &sync.Mutex{})
lock.(*sync.Mutex).Unlock()
}

func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (Metadata, error) {


+ 2
- 2
server/server.go 파일 보기

@@ -282,7 +282,7 @@ type Server struct {

profilerEnabled bool

locks map[string]*sync.Mutex
locks sync.Map

maxUploadSize int64
rateLimitRequests int
@@ -321,7 +321,7 @@ type Server struct {

func New(options ...OptionFn) (*Server, error) {
s := &Server{
locks: map[string]*sync.Mutex{},
locks: sync.Map{},
}

for _, optionFn := range options {


불러오는 중...
취소
저장