diff --git a/history/file_scribe.go b/history/file_scribe.go index c0f3c08f6..c974876f7 100644 --- a/history/file_scribe.go +++ b/history/file_scribe.go @@ -37,7 +37,7 @@ const ( ) type FileScribe struct { - mu sync.RWMutex + mu sync.Mutex fileRoot string gitCommand string destinations records @@ -65,8 +65,6 @@ func NewFileScribe(fileRoot string) (*FileScribe, error) { } func (s *FileScribe) Record(rec *Record, out *int) error { - s.mu.Lock() - defer s.mu.Unlock() var fileToSave string switch { case strings.HasPrefix(rec.Key, DESTINATION_PREFIX): @@ -104,6 +102,8 @@ func (s *FileScribe) Record(rec *Record, out *int) error { } func (s *FileScribe) gitInit() error { + s.mu.Lock() + defer s.mu.Unlock() if _, err := os.Stat(s.fileRoot); os.IsNotExist(err) { if err := os.MkdirAll(s.fileRoot, os.ModeDir|0755); err != nil { return errors.New(" Error creating history folder: " + err.Error()) @@ -144,6 +144,8 @@ func (s *FileScribe) gitCommit() error { } func (s *FileScribe) load(filename string) error { + s.mu.Lock() + defer s.mu.Unlock() f, err := os.Open(filepath.Join(s.fileRoot, filename)) if err != nil { return err @@ -167,6 +169,8 @@ func (s *FileScribe) load(filename string) error { } func (s *FileScribe) save(filename string) error { + s.mu.Lock() + defer s.mu.Unlock() f, err := os.Create(filepath.Join(s.fileRoot, filename)) if err != nil { return err diff --git a/history/mock_scribe.go b/history/mock_scribe.go index 152fce446..7b2a5af65 100644 --- a/history/mock_scribe.go +++ b/history/mock_scribe.go @@ -28,7 +28,7 @@ import ( ) type MockScribe struct { - sync.RWMutex + sync.Mutex destinations records ratingProfiles records DestBuf bytes.Buffer @@ -40,8 +40,6 @@ func NewMockScribe() (*MockScribe, error) { } func (s *MockScribe) Record(rec *Record, out *int) error { - s.Lock() - defer s.Unlock() switch { case strings.HasPrefix(rec.Key, DESTINATION_PREFIX): s.destinations = s.destinations.SetOrAdd(&Record{rec.Key[len(DESTINATION_PREFIX):], rec.Object}) @@ -55,6 +53,8 @@ func (s *MockScribe) Record(rec *Record, out *int) error { } func (s *MockScribe) save(filename string) error { + s.Lock() + defer s.Unlock() switch filename { case DESTINATIONS_FILE: s.DestBuf.Reset() diff --git a/mediator/mediator.go b/mediator/mediator.go index 5bd2c2600..79f0f00f9 100644 --- a/mediator/mediator.go +++ b/mediator/mediator.go @@ -202,7 +202,7 @@ func (self *Mediator) getCostsFromRater(cdr utils.CDR) (*engine.CallCost, error) // If the mediator calculated a price it will write it to logdb self.storDb.LogCallCost(cdr.GetCgrId(), engine.MEDIATOR_SOURCE, cc) } - return cc, nil + return cc, err } // Parse the files and get cost for every record