Opened 15 months ago

Closed 3 months ago

#7646 closed bug (fixed)

resource busy (file is locked) with multi-threaded file ops

Reported by: StefanWehr Owned by: simonmar
Priority: high Milestone: 7.6.3
Component: libraries/base Version: 7.6.2
Keywords: Cc: leuschner@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The sample program attached creates 10 worker threads, each of which takes a different file name. Each worker thread then writes the file, reads the file, writes the file and so on. File operations use *strict IO*.

When compiled without -threaded everything is ok, that is, the program goes on forever without any error messages.

But with -threaded, the program quickly fails with ERROR in worker 4: 4: openBinaryFile: resource busy (file is locked).

Tested under Mac OSX 10.8.2 and Linux.
Tested with both GHC 7.6.1 and 7.6.2.

I could reproduce the bug without +RTS -N -RTS and with this RTS option. A colleague of mine reports that it needs +RTS -N2 -RTS to reproduce the bug.

Attachments (1)

GhcBug.hs (1.1 KB) - added by StefanWehr 15 months ago.
Testcase for reproducing the bug

Download all attachments as: .zip

Change History (8)

Changed 15 months ago by StefanWehr

Testcase for reproducing the bug

comment:1 Changed 15 months ago by dleuschner

  • Cc leuschner@… added

comment:2 Changed 15 months ago by carter

I can replicate the bug on my machine.

Interestingly enough, when I use BS.appendFile instead of BS.writeFile,
the bug doesn't happen!

I will try to use that information to sort out what may be happening. (or at least attempt to)

comment:3 Changed 15 months ago by dleuschner

  • Version changed from 7.6.1 to 7.6.2

Thank you for looking into this issue, Carter! I assume it might affect more users than we might think, because the error message is typically associated with the lazy-IO problem of first (incompletely) reading and then writing.

For me it still doesn't work with appendFile. The output still is:

$ ghc -threaded -rtsopts --make GhcBug.hs && ./GhcBug +RTS -N2
started worker 3
started worker 2
started worker 5
started worker 7
started worker 9
started worker 1
started worker 4
started worker 6
started worker 8
started worker 10
GhcBug: ERROR in worker 1: 1: openBinaryFile: resource busy (file is locked)
ERROR in worker 1: 1: openBinaryFile: resource busy (file is locked)

comment:4 Changed 15 months ago by simonmar

  • Component changed from Runtime System to libraries/base
  • Difficulty set to Unknown
  • Milestone set to 7.6.3
  • Owner set to simonmar
  • Priority changed from normal to high

Fix coming, thanks for the report.

comment:5 Changed 15 months ago by simonmar

  • Status changed from new to merge
commit fbd4b4c2587636811d464040e349d81fac9e1121
Author: Simon Marlow <marlowsd@gmail.com>
Date:   Mon Feb 4 12:08:00 2013 +0000

    Release the FD lock before calling close() (#7646)

comment:6 Changed 15 months ago by dleuschner

Thank you very much, Simon! We will miss you! :-)

comment:7 Changed 3 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from merge to closed

Fixed in 7.8/HEAD.

Note: See TracTickets for help on using tickets.