Skip to content

Commit

Permalink
fixup: hack for re-reads
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Aug 30, 2023
1 parent 7cb3cdd commit bdb2c5b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions grpc-sync-server/pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net"
"os"
"time"

"github.com/fsnotify/fsnotify"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -126,6 +127,13 @@ func (s *SyncImpl) readFlags() ([]byte, error) {

for _, path := range s.filePaths {
bytes, err := os.ReadFile(path)
if len(bytes) == 0 {
// this is a fitly hack
// file writes are NOT atomic and often when they are changed they have transitional empty states
// this "re-reads" the file in these cases 10ms later
time.Sleep(10 * time.Millisecond)
bytes, err = os.ReadFile(path)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit bdb2c5b

Please sign in to comment.