Sitelet https://github.com/nodejs/node/issues/1634
Skip to content

Race condition on history file with multiple REPLs #1634

Description

@rvagg

via @substack

<substack> found another repl history bug, if you have 2 repls open at once it doesn't lock the file
<substack> but a bit hard to reproduce since they've got to be writing at the same time
<substack> but I already ran into it just doing normal things with 2 repls open at once

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    on May 6, 2015
  2. chrisdickinson commented on May 7, 2015

    @chrisdickinson
    Contributor

    Looking into this. I see two possible solutions. If anyone has a better idea, please let me know!

    1. Use tmp files + rename to atomically swap the node history file.
    2. 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.
  3. bnoordhuis commented on May 7, 2015

    @bnoordhuis
    Member

    Option 1 can work as long as the files are on the same mount. Option 2 has portability issues and is unreliable with NFS.

  4. rvagg commented on May 7, 2015

    @rvagg
    MemberAuthor

    can we see what bash does and copy that?

  5. chrisdickinson commented on May 7, 2015

    @chrisdickinson
    Contributor

    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.

  6. ivan commented on May 13, 2015

    @ivan
    SponsorContributor

    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.

  7. evanlucas commented on Feb 2, 2016

    @evanlucas
    Contributor

    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?

  8. Fishrock123 commented on Mar 16, 2016

    @Fishrock123
    Contributor

    Locking would probably be desirable if someone wants to take it up. It would be pretty complex though.

  9. lance commented on May 25, 2016

    @lance
    Member

    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?

  10. Fishrock123 commented on May 25, 2016

    @Fishrock123
    Contributor

    @lance either or. I'd prefer interleaved. Most terminals do last-write-is-latest-history.

  11. removed
    good first issueIssues that are suitable for first-time contributors.
    on Aug 3, 2016
  12. lance commented on Aug 3, 2016

    @lance
    Member

    Removed good-first-contribution label as I don't think this is the case. At least not if #7005 is any indication.

  13. Trott commented on Jul 9, 2017

    @Trott
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

confirmed-bugIssues and PRs for confirmed bugs.replIssues and PRs related to the REPL subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions