da46ffea15a0

3.9.0: let only this host's folder locks use the pid check, and bump the version for schema 2

time
2026-11-17 15:11 UTC · 1 week ago
machine
Junes-MacBook-Pro.local
agent
claude-opus-5-5
session
verify review findings
parent
a03dc73b7a11
4 files VERSION+1 −1src/remote/folder.v+9 −5src/remote/folder_test.v+9 −3v.mod+1 −1
VERSION+1 −1
@@ -1 +1 @@1-3.8.71+3.9.0

view file

src/remote/folder.v+9 −5
@@ -165,7 +165,9 @@165165 fn take_lock(path string) !bool {166166 	pid := '${os.getpid()}'167167 	fresh := '${path}.${pid}.${time.now().unix_nano()}'168-	os.write_file(fresh, pid)!168+	// The host goes with the pid: on a shared folder the lock may be another machine's.169+	owner := '${os.hostname() or { '' }} ${pid}'170+	os.write_file(fresh, owner)!169171 	defer {170172 		os.rm(fresh) or {}171173 	}@@ -173,7 +175,7 @@173175 		if os.exists(path) {174176 			return false175177 		}176-		return create_exclusive(path, pid.bytes())178+		return create_exclusive(path, owner.bytes())177179 	}178180 	return true179181 }@@ -191,15 +193,17 @@191193 // clear_stale_lock removes a lock left behind by a writer that died mid-swap.192194 // A lock a minute old is not a swap in progress; it is debris, and leaving it193195 // would block this remote for ever. The pid inside it is checked first: deleting194-// a lock whose writer is still alive would let a second writer in.196+// a lock whose writer is still alive would let a second writer in. Only a lock197+// this machine wrote names a pid worth asking about; for any other, age decides.195198 fn clear_stale_lock(path string) {196199 	info := os.stat(path) or { return }197200 	if time.now().unix() - info.mtime <= 60 {198201 		return199202 	}200203 	body := os.read_file(path) or { return }201-	pid := body.trim_space().int()202-	if pid > 0 && C.koh_pid_alive(pid) != 0 {204+	host := body.trim_space().all_before_last(' ')205+	pid := body.trim_space().all_after_last(' ').int()206+	if host != '' && host == (os.hostname() or { '' }) && pid > 0 && C.koh_pid_alive(pid) != 0 {203207 		return204208 	}205209 	// The file may have been replaced between the two reads; only the exact

view file

src/remote/folder_test.v+9 −3
@@ -121,7 +121,7 @@121121 	guard := os.join_path(dir, 'key.lock')122122 	assert take_lock(guard)!123123 	assert !take_lock(guard)!124-	assert os.read_file(guard)! == '${os.getpid()}'124+	assert os.read_file(guard)! == '${os.hostname()!} ${os.getpid()}'125125 	release_lock(guard)126126 	assert take_lock(guard)!127127 	release_lock(guard)@@ -134,13 +134,19 @@134134 	}135135 	guard := os.join_path(base, 'key.lock')136136 	old := time.now().unix() - 120137+	host := os.hostname()!137138 	// Our own pid is alive, so an old lock is still a writer's.138-	os.write_file(guard, '${os.getpid()}')!139+	os.write_file(guard, '${host} ${os.getpid()}')!139140 	os.utime(guard, old, old)!140141 	clear_stale_lock(guard)141142 	assert os.exists(guard)142143 	// A pid nothing holds is debris, and clears.143-	os.write_file(guard, '2000000')!144+	os.write_file(guard, '${host} 2000000')!145+	os.utime(guard, old, old)!146+	clear_stale_lock(guard)147+	assert !os.exists(guard)148+	// Another machine's pid says nothing about this one's processes: age alone decides.149+	os.write_file(guard, 'another-machine ${os.getpid()}')!144150 	os.utime(guard, old, old)!145151 	clear_stale_lock(guard)146152 	assert !os.exists(guard)

view file

v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 	name: 'koh3'3-	version: '3.8.7'3+	version: '3.9.0'44 	description: 'One SQLite file per repo, one line of history.'55 	license: 'MIT'66 }

view file