fix(syncthing): use separate lock file instead of locking the certificate (fixes #10053) (#10054)

Apparently that nukes the cert under some circumstances on some Windows
🤷
This commit is contained in:
Jakob Borg
2025-04-12 14:49:23 +02:00
parent 7f3c8dbff1
commit 190a59842c
2 changed files with 10 additions and 2 deletions
+8 -2
View File
@@ -376,7 +376,7 @@ func (options serveOptions) Run() error {
if options.Upgrade { if options.Upgrade {
release, err := checkUpgrade() release, err := checkUpgrade()
if err == nil { if err == nil {
lf := flock.New(locations.Get(locations.CertFile)) lf := flock.New(locations.Get(locations.LockFile))
locked, err := lf.TryLock() locked, err := lf.TryLock()
if err != nil { if err != nil {
l.Warnln("Upgrade:", err) l.Warnln("Upgrade:", err)
@@ -386,6 +386,8 @@ func (options serveOptions) Run() error {
} else { } else {
err = upgrade.To(release) err = upgrade.To(release)
} }
_ = lf.Unlock()
_ = os.Remove(locations.Get(locations.LockFile))
} }
if err != nil { if err != nil {
l.Warnln("Upgrade:", err) l.Warnln("Upgrade:", err)
@@ -546,7 +548,7 @@ func syncthingMain(options serveOptions) {
} }
// Ensure we are the only running instance // Ensure we are the only running instance
lf := flock.New(locations.Get(locations.CertFile)) lf := flock.New(locations.Get(locations.LockFile))
locked, err := lf.TryLock() locked, err := lf.TryLock()
if err != nil { if err != nil {
l.Warnln("Failed to acquire lock:", err) l.Warnln("Failed to acquire lock:", err)
@@ -692,6 +694,10 @@ func syncthingMain(options serveOptions) {
pprof.StopCPUProfile() pprof.StopCPUProfile()
} }
// Best effort remove lockfile, doesn't matter if it succeeds
_ = lf.Unlock()
_ = os.Remove(locations.Get(locations.LockFile))
os.Exit(int(status)) os.Exit(int(status))
} }
+2
View File
@@ -33,6 +33,7 @@ const (
AuditLog LocationEnum = "auditLog" AuditLog LocationEnum = "auditLog"
GUIAssets LocationEnum = "guiAssets" GUIAssets LocationEnum = "guiAssets"
DefFolder LocationEnum = "defFolder" DefFolder LocationEnum = "defFolder"
LockFile LocationEnum = "lockFile"
) )
type BaseDirEnum string type BaseDirEnum string
@@ -124,6 +125,7 @@ var locationTemplates = map[LocationEnum]string{
AuditLog: "${data}/audit-%{timestamp}.log", AuditLog: "${data}/audit-%{timestamp}.log",
GUIAssets: "${config}/gui", GUIAssets: "${config}/gui",
DefFolder: "${userHome}/Sync", DefFolder: "${userHome}/Sync",
LockFile: "${data}/syncthing.lock",
} }
var locations = make(map[LocationEnum]string) var locations = make(map[LocationEnum]string)