views:

27

answers:

1

We're creating a web service where we're writing files to disk. Sometimes these files will be read at the same time as they are written.

If we do this - writing and reading from the same file - we sometimes end up with files that are of the same length, but where some of the data inside are not the same. So with a 350mb file we get maybe 20-40 bytes that differs.

This problem mostly occur if we have 3-4 files that are being written and read at the same time. Could this problem be because there is no guarantee that after a "write" to a disk, that the data is actually written, i.e., the disk is being asynchronous.

Also, the computer we're testing on is just a standard macbook pro, so no fancy disks of any kind.

The bug might be somewhere else, but we just wanted to ask the question and see if anybody knew something about this writing+reading thing.

A: 

All modern OSs support concurrent reading and writing to files (obviously, given a single writer). So this is not an OS level bug. But do make sure you do not have multiple threads/processes trying to append data to the file.

Check your application code. Check the buffers you are using. Make sure your application is synchronized and there are no race conditions between readers and writers.

Yuval A
Thanks. We thought this was the case, but we can't find the bug, so we thought we'd ask.
freeall
Post some relevant code and maybe we can help zoom in on the problem...
Yuval A
We think we found the bug. It was in node.js. See more about it here, http://pastebin.com/2LReijQC.
freeall