#191: Handle memory issue caused by migration from Service to Endpoint

This commit is contained in:
TwiN 2021-10-24 21:20:01 -04:00
parent a4e9d8e9b0
commit 3a4ab62ddd

View File

@ -2,7 +2,11 @@ package memory
import ( import (
"encoding/gob" "encoding/gob"
"io/fs"
"io/ioutil"
"log"
"sort" "sort"
"strings"
"sync" "sync"
"time" "time"
@ -40,6 +44,20 @@ func NewStore(file string) (*Store, error) {
if len(file) > 0 { if len(file) > 0 {
_, err := store.cache.ReadFromFile(file) _, err := store.cache.ReadFromFile(file)
if err != nil { if err != nil {
// XXX: Remove the block below in v4.0.0
if data, err2 := ioutil.ReadFile(file); err2 == nil {
isFromOldVersion := strings.Contains(string(data), "*core.ServiceStatus")
if isFromOldVersion {
log.Println("WARNING: Couldn't read file due to recent change in v3.3.0, see https://github.com/TwiN/gatus/issues/191")
log.Println("WARNING: Will automatically rename old file to " + file + ".old and overwrite the current file")
if err = ioutil.WriteFile(file+".old", data, fs.ModePerm); err != nil {
log.Println("WARNING: Tried my best to keep the old file, but it wasn't enough. Sorry, your file will be overwritten :(")
}
// Return the store regardless of whether there was an error or not
return store, nil
}
}
// XXX: Remove the block above in v4.0.0
return nil, err return nil, err
} }
} }