You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Wicksteed, Charles" <Wi...@logica.com> on 2002/03/08 14:39:42 UTC

PR 9769 fix, mod_proxy cannot delete file under Win32

Hi,

Re PR 9769 -- mod_proxy cannot delete old cache file under Win32.
(Cache stores obsolete files)

The problem described in PR 9769 has been causing us some trouble,
but I have found out what is causing it and added a fix to my copy
of the code.

There is however still a remaining and more tricky problem with
being unable to delete files which are still open, if you get
multiple overlapping requests for the same URL.  This is likely
in our application, where it is a reverse proxy.

First the solution to PR 9769:

The problem arises when a cache file has passed its Expires date,
the proxy does a GET If-Modified-Since to the remote server, the
file has changed and the server returns 200 OK.  Under these
circumstances the path through the code is such that the original
cache file is still open when it tries to delete it, which causes
the delete to fail under Win32.  The response goes back to the client
OK, saying "MISS", but the old expired cache file remains where it was.
This happens on every subsequent request for that URL until the cache
file is deleted.

To fix it, I added these lines just before "return DECLINED;"
at line 1630 in proxy_cache.c v1.76 (as included in Apache 1.3.23).
To help pinpoint the position, this is about 11 lines on from the
comment "copy the body".  At the end of ap_proxy_cache_update().

    /* Close origfp, otherwise we can't delete the file later, on WIN32 */
    if (c->origfp) {
        ap_pclosef(r->pool, ap_bfileno(c->origfp, B_WR));
    }

If you need more information, get back to me.

Now the other problem:

mod_proxy holds the original cache file open during the time while
the GET If-Modified-Since is processed by the remote server.  If
another request comes in for the same URL during this time, the
original thread will be unable to update the cache file, because
the second thread will be holding it open.

A partial solution is to close the cache file, then open it again
when the response is in, reading the headers again to get us back
to the same point in the file.  The file is still held open while
the response is streamed back to the client though, and may prevent
the file being updated.

A better solution is to lock the file in some way while the request
is sent to the remote server.  A second request for the same URL would
wait until the lock is released, then return the fresh body.
This has the advantage of not hitting the remote server twice, which
is what a reverse proxy is for.

Regards,

Charles   wicksteedc@logica.com
Logica plc, London, UK.

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.

Re: PR 9769 fix, mod_proxy cannot delete file under Win32

Posted by Graham Leggett <mi...@sharp.fm>.
"Wicksteed, Charles" wrote:

> Re PR 9769 -- mod_proxy cannot delete old cache file under Win32.
> (Cache stores obsolete files)
> 
> The problem described in PR 9769 has been causing us some trouble,
> but I have found out what is causing it and added a fix to my copy
> of the code.

The proxy was originally designed to work on unix, which has none of the
limitations of windows when it comes to opening files (you can open a
file more than once, you can delete a file that is open by other threads
safely, etc).

Can someone with a knowledge of windows look at this?

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."