
Hi, After a partial rewrite of my webserver, it is suffering from locked files: /path/to/file: openBinaryFile: resource busy (file is locked) The file in question really shouldn't be locked: - Only my server knows of the file's existence. - Only one thread accesses the file. - The thread accesses the file multiple times in quick succession, opening and closing it each time, but debugging statements show that it is properly closed before it is reopened. I tried opening, reading/writing and closing a file continuously for some time in an isolated environment, and that works without problems. Also, my server did not have this file locking problem before the rewrite, and the rewrite did not touch the part of the code that accesses the file. This suggests that the locking is somehow triggered by the specific access pattern of my code, if that is even possible. Does anyone know what could cause this locking and/or how to prevent it? I'm using ghc 6.4 on gentoo linux (amd64). Thanks and greetings, Arie

Are you using hGetContents? If you are, take a closer look at the
documentation. The function creates a lazy stream and until you finish
reading from it the file will be in the "semi-closed" state (which
means it will be locked).
On 12/3/06, Arie Peterson
Hi,
After a partial rewrite of my webserver, it is suffering from locked files:
/path/to/file: openBinaryFile: resource busy (file is locked)
The file in question really shouldn't be locked: - Only my server knows of the file's existence. - Only one thread accesses the file. - The thread accesses the file multiple times in quick succession, opening and closing it each time, but debugging statements show that it is properly closed before it is reopened.
I tried opening, reading/writing and closing a file continuously for some time in an isolated environment, and that works without problems.
Also, my server did not have this file locking problem before the rewrite, and the rewrite did not touch the part of the code that accesses the file.
This suggests that the locking is somehow triggered by the specific access pattern of my code, if that is even possible.
Does anyone know what could cause this locking and/or how to prevent it?
I'm using ghc 6.4 on gentoo linux (amd64).
Thanks and greetings,
Arie
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Vyacheslav Akhmechet
Are you using hGetContents? If you are, take a closer look at the documentation. The function creates a lazy stream and until you finish reading from it the file will be in the "semi-closed" state (which means it will be locked).
No. I read/write using functions from SerTH, a serialisation library. I assume that the decoding function does not have hGetContents's lazy behaviour. At any rate, I close the file with hClose after use.

I wish to pass a 2 dimensional array to use in a back-tracking algorithm. Since I will be doing lots of inserts, a Data.Array is unsuitable. It seems that a Map Int (Map Int a) is the most suitable structure, but this seems cumbersome. Is there anything more appropriate? -- Tony Morris http://tmorris.net/

At 12:25 PM +1000 12/4/06, Tony Morris wrote:
I wish to pass a 2 dimensional array to use in a back-tracking algorithm. Since I will be doing lots of inserts, a Data.Array is unsuitable. It seems that a Map Int (Map Int a) is the most suitable structure, but this seems cumbersome.
Is there anything more appropriate?
Map (Int, Int) a ?

You might want to consider using a DiffArray, though if the
backtracking is of just the wrong sort, you might get worse
performance than you want. Updates are O(length xs) where xs is the
list of updates to be performed (so O(1) in the singleton case), but
lookups into older versions of the array get slower by a constant
amount every time an update is performed. (The semantics are
referentially transparent, the performance is not.) However, updating
an old version will cause a fresh copy to be made, and lookups will be
fast again after that.
On 03/12/06, Tony Morris
I wish to pass a 2 dimensional array to use in a back-tracking algorithm. Since I will be doing lots of inserts, a Data.Array is unsuitable. It seems that a Map Int (Map Int a) is the most suitable structure, but this seems cumbersome.
Is there anything more appropriate?
-- Tony Morris http://tmorris.net/
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Sun, Dec 03, 2006 at 08:13:37PM +0100, Arie Peterson wrote:
Does anyone know what could cause this locking and/or how to prevent it?
Nothing else springs to mind. Are you able to send an example that shows the problem? (obviously the smaller the example, the better). Thanks Ian

Ian Lynagh wrote:
Does anyone know what could cause this locking and/or how to prevent it?
Nothing else springs to mind. Are you able to send an example that shows the problem? (obviously the smaller the example, the better).
I'll try to cut down the offending program to a workable size. This will take a while. By the way, the rewrite I mentioned (which introduced the unwanted locking) did not touch the code which deals with the file, but it did change the program to load that code dynamically (using hs-plugins). Could that possibly be related to the file locking problem? Thanks, Arie

Yes. I've run into similar issues with hs-plugins (albeit not the
same). What platform are you running on? How are you compiling your
code? Try compiling it with the -threaded flag and see if it fixes
your problem.
On 12/6/06, Arie Peterson
Ian Lynagh wrote:
Does anyone know what could cause this locking and/or how to prevent it?
Nothing else springs to mind. Are you able to send an example that shows the problem? (obviously the smaller the example, the better).
I'll try to cut down the offending program to a workable size. This will take a while.
By the way, the rewrite I mentioned (which introduced the unwanted locking) did not touch the code which deals with the file, but it did change the program to load that code dynamically (using hs-plugins). Could that possibly be related to the file locking problem?
Thanks,
Arie
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Vyacheslav Akhmechet wrote:
Yes. I've run into similar issues with hs-plugins (albeit not the same). What platform are you running on? How are you compiling your code? Try compiling it with the -threaded flag and see if it fixes your problem.
My platform is amd64 (x86_64). I usually compile with '--make -O2'. I just tried adding the '-threaded' flag, but that does not seem to change anything. Thanks for the suggestion though! When I get around to it, I'll check whether a minimal program that accesses a file from dynamically loaded code shows this locking problem. Greetings, Arie
participants (7)
-
Arie Peterson
-
Cale Gibbard
-
Dean Herington
-
Ian Lynagh
-
Neil Mitchell
-
Tony Morris
-
Vyacheslav Akhmechet