Skip to main content

try_lock

Function try_lock 

Source
pub fn try_lock(offset_path: &Path) -> Result<Option<File>>
Expand description

Take the exclusive lock on the file offset_path keys, without waiting. None means another hook of the session holds it.

A hook holds it from reading the file to writing its new offset. Parallel hooks of one session run concurrently, and without it two of them can read from one offset, the one that read less can write its offset last, and the next hook re-sends the rest from that offset: same lines, new chunk_indexes, stored twice. A hook that finds the lock taken skips the file instead of waiting (the holder may spend the whole delivery budget); a later hook, at the latest that subagent’s SubagentStop, sends what the holder did not read. The OS drops the lock when its holder exits, even if killed.