Skip to content

Commit

Permalink
Merge 0956e06 into backport/gh-19720-empty-server-metadata/logically-…
Browse files Browse the repository at this point in the history
…distinct-bird
  • Loading branch information
hc-github-team-consul-core authored Jan 5, 2024
2 parents 5d9177d + 0956e06 commit c38e091
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hashicorp/hcp-scada-provider/capability"
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
"github.com/rboyer/safeio"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/grpc"
Expand Down Expand Up @@ -4668,7 +4669,12 @@ func (a *Agent) persistServerMetadata() {
continue
}

f.Close()
sf := f.(*safeio.File)
if err := sf.Commit(); err != nil {
a.logger.Error("failed to commit server metadata", "error", err)
continue
}
sf.Close()
case <-a.shutdownCh:
return
}
Expand Down
4 changes: 3 additions & 1 deletion agent/consul/server_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"io"
"os"
"time"

"github.com/rboyer/safeio"
)

// ServerMetadataFile is the name of the file on disk that server metadata
Expand All @@ -31,7 +33,7 @@ func (md *ServerMetadata) IsLastSeenStale(d time.Duration) bool {
// OpenServerMetadata is a helper function for opening the server metadata file
// with the correct permissions.
func OpenServerMetadata(filename string) (io.WriteCloser, error) {
return os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
return safeio.OpenFile(filename, 0600)
}

type ServerMetadataReadFunc func(filename string) (*ServerMetadata, error)
Expand Down

0 comments on commit c38e091

Please sign in to comment.