Ticket #1994 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

Data.ByteStirng.Lazy.hGetContents doesn't unlock i-node

Reported by: guest Owned by:
Priority: normal Milestone:
Component: libraries (other) Version: 6.8.2
Keywords: lazy IO Cc: snak@…, dons@…
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I found that Data.ByteStirng?.Lazy.hGetContents doesn't unlock i-node even after retreiving whole contents. Because of this and the fact that file locking mechanism of GHC uses i-node, sometimes it causes a problem whose cause is hard to find.

See this example assuming file 'a' already exists:

testB = forM [1..] $ \_ -> do
    r <- B.readFile "a" >>= \r -> return $! B.length r `seq` r
    B.writeFile "b" (B8.pack "abc")
    renameFile "b" "a"

When I run this test on GHCi, it shows this error:

*Main> testB *** Exception: b: openBinaryFile: resource busy (file is locked)

I presume that this error happened because:

  1. readFile locks the i-node of 'a' and continues to lock after reading whole contents
  2. writeFile writes contents to 'b'
  3. Maybe GC runs and closes the handle but doesn't unlock i-node
  4. renaming 'b' to 'a' causes free the i-node of 'a'
  5. readFile locks another i-node of 'a'
  6. writeFile reuses the first i-node of 'a' which is still locked

It is very difficult to find that readFile causes a problem, because an error occures in writeFile.

I'm not sure this is a problem of ByteString? or GC, but this problem doesn't occur when I use System.IO.hGetContents because it closes the handle and unlocks the i-node after retrieving whole contents.

Change History

Changed 5 years ago by dons

  • cc dons@… added
  • keywords lazy IO added
  • status changed from new to closed
  • resolution set to fixed
  • architecture changed from x86 to Multiple

I'm not sure how we missed this, but yes, the lazy bytestring lazy IO operations weren't finalizing the resource once EOF was encountered. I've pushed a patch to fix this, and your test programs now work.

Can you confirm that with the latest darcs repository, your code now works?

darcs get  http://darcs.haskell.org/bytestring

Changed 5 years ago by guest

Yes, I confirmed that our code worked fine with the latest repository. Thank you.

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple
Note: See TracTickets for help on using tickets.