Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-3274

eof in couch_file can be incorrect after error


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:


      It's possible for a file:write call to write some of the requested data but then return an error (

      {error, enospc}

      , for example).

      In 2010 we started tracking eof in couch_file state, where previously we called file:position(Fd, eof) and used that value, which was always correct. In success cases we advance the eof value by the correct amount but in error cases we don't advance it at all.

      A simple fix is to call file:position(Fd, eof) in the error cases and set the eof field to that value.

      The upshot of this bug is that data written to the file once eof is wrong is essentially corrupt in that we'll look for it at the wrong offsets. Given this would typically when a filesystem runs completely out of space, in most cases it would not cause issues (we wouldn't be able to write a header that pointed to this) but if space were then recovered (and the couch_file had not closed or crashed) then corruption seems assured.

      I have a patch for this and I certainly welcome opinions on severity (and, indeed, if I'm flat wrong).




            • Assignee:
              rnewson Robert Newson
            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created: