The only problem with this patch is that it occasionally causes the WriteFile to block indefinitely and all the other worker threads block on apr_file_lock waiting for the file lock. I can send several thousand requests through the server before it hangs. I don't see anything obviously wrong here or in apr_file_lock|unlock. Obviously I will not commit this until we figure out and fix what is causing the WriteFile block.
I generally see the hang writing to the access log. I did see a hang writing to the error log at startup once. Bill --- readwrite.c 19 Sep 2002 12:20:20 -0000 1.1.1.1 +++ readwrite.c 25 Oct 2002 13:44:53 -0000 @@ -303,15 +303,28 @@ apr_thread_mutex_unlock(thefile->mutex); return rv; } else { - if (thefile->pOverlapped && !thefile->pipe) { - thefile->pOverlapped->Offset = (DWORD)thefile->filePtr; - thefile->pOverlapped->OffsetHigh = (DWORD)(thefile->filePtr >> 32); - } - else if (!thefile->pipe && thefile->append) { + if (thefile->append && !thefile->pipe) { + int rc; + rc = apr_file_lock(thefile, APR_FLOCK_EXCLUSIVE); + if (rc != APR_SUCCESS) { + rc = APR_SUCCESS; + } SetFilePointer(thefile->filehand, 0, NULL, FILE_END); + rv = WriteFile(thefile->filehand, buf, *nbytes, &bwrote, NULL); + rc = apr_file_unlock(thefile); + if (rc != APR_SUCCESS) { + rc = APR_SUCCESS; + } + } + else { + if (thefile->pOverlapped && !thefile->pipe) { + thefile->pOverlapped->Offset = (DWORD)thefile->filePtr; + thefile->pOverlapped->OffsetHigh = (DWORD)(thefile->filePtr >> 32); + } + rv = WriteFile(thefile->filehand, buf, *nbytes, &bwrote, + thefile->pOverlapped); } - if (WriteFile(thefile->filehand, buf, *nbytes, &bwrote, - thefile->pOverlapped)) { + if (rv) { *nbytes = bwrote; rv = APR_SUCCESS; } $