Repository navigation
Race condition on history file with multiple REPLs #1634
Description
Activity
- addedreplIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
on May 6, 2015 Looking into this. I see two possible solutions. If anyone has a better idea, please let me know!
- Use tmp files + rename to atomically swap the node history file.
- Use fcntl / flock'ing (or a similar mechanism) and make sure that only one cooperating node process at a time is writing to the file.
Option 1 can work as long as the files are on the same mount. Option 2 has portability issues and is unreliable with NFS.
can we see what bash does and copy that?
What about mmap'ing the file & setting a semaphore byte? This might be a bit too heavyweight of a solution, since it would require mmap support be added to libuv.
Just for the record: this happens so frequently not because of racing writes but because both REPLs have the history file open in 'w' mode, one REPL exits and writes some history, and the other REPL exits and writes a shorter history, leaving behind some trailing bytes from the longer history.
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Aug 3, 2015 It seems like since we moved away from using json, this is no longer prevalent. Do we still need to implement some sort of locking to prevent corruption?
- addedgood first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on Mar 16, 2016 Locking would probably be desirable if someone wants to take it up. It would be pretty complex though.
I started working on a locking implementation for this, but I'm not totally clear on the desired behavior. If multiple REPLs are open should history be interleaved? Or is it last-write-wins behavior?
@lance either or. I'd prefer interleaved. Most terminals do last-write-is-latest-history.
- removedgood first issueIssues that are suitable for first-time contributors.Issues that are suitable for first-time contributors.
on Aug 3, 2016 Removed
good-first-contributionlabel as I don't think this is the case. At least not if #7005 is any indication.This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that.
via @substack