mirror of https://github.com/dirtbags/moth.git
Fixing some locking issues
This commit is contained in:
parent
9793de315a
commit
9a8ec19908
|
@ -283,7 +283,6 @@ func (s *State) SetTeamName(teamID, teamName string) error {
|
|||
return fmt.Errorf("team ID not found in list of valid team IDs")
|
||||
}
|
||||
|
||||
|
||||
s.teamNameLock.RLock()
|
||||
_, ok := s.teamNames[teamID]
|
||||
s.teamNameLock.RUnlock()
|
||||
|
@ -452,7 +451,7 @@ func (s *State) flushPointsLog(newPoints award.List) error {
|
|||
defer logf.Close()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Can't write to points log: ", err)
|
||||
return fmt.Errorf("Can't write to points log: %s", err)
|
||||
}
|
||||
for _, pointEntry := range newPoints {
|
||||
fmt.Fprintln(logf, pointEntry.String())
|
||||
|
@ -569,21 +568,24 @@ func (s *State) collectPoints() {
|
|||
} else {
|
||||
log.Print("Award: ", awd.String())
|
||||
|
||||
{
|
||||
s.pointsLogFileLock.Lock()
|
||||
defer s.pointsLogFileLock.Unlock()
|
||||
|
||||
logf, err := s.OpenFile("points.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Print("Can't append to points log: ", err)
|
||||
s.pointsLogFileLock.Unlock()
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(logf, awd.String())
|
||||
logf.Close()
|
||||
s.pointsLogFileLock.Unlock()
|
||||
}
|
||||
|
||||
// Stick this on the cache too
|
||||
s.pointsLock.Lock()
|
||||
defer s.pointsLock.Unlock()
|
||||
s.pointsLog = append(s.pointsLog, awd)
|
||||
s.pointsLock.Unlock()
|
||||
}
|
||||
|
||||
if err := s.Remove(filename); err != nil {
|
||||
|
@ -746,6 +748,8 @@ func (s *State) updateCaches() {
|
|||
s.pointsLock.RLock()
|
||||
defer s.pointsLock.RUnlock()
|
||||
|
||||
// Re-read the points log
|
||||
{
|
||||
s.pointsLogFileLock.RLock()
|
||||
defer s.pointsLogFileLock.RUnlock()
|
||||
|
||||
|
@ -766,9 +770,9 @@ func (s *State) updateCaches() {
|
|||
pointsLog = append(pointsLog, cur)
|
||||
}
|
||||
|
||||
|
||||
s.pointsLog = pointsLog
|
||||
}
|
||||
}
|
||||
|
||||
// Only do this if the teams directory has a newer mtime; directories with
|
||||
// hundreds of team names can cause NFS I/O storms
|
||||
|
@ -806,12 +810,15 @@ func (s *State) updateCaches() {
|
|||
}
|
||||
}
|
||||
|
||||
// Re-read the messages file
|
||||
{
|
||||
s.messageFileLock.RLock()
|
||||
defer s.messageFileLock.RUnlock()
|
||||
|
||||
if bMessages, err := afero.ReadFile(s, "messages.html"); err == nil {
|
||||
s.messages = string(bMessages)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *State) refresh() {
|
||||
|
|
Loading…
Reference in New Issue