Jetty
  1. Jetty
  2. JETTY-60

NIO memory mapped files keep static content write-locked on Windows

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 6.0.0beta15
    • Fix Version/s: None
    • Component/s: NIO
    • Labels:
      None
    • Environment:
      Windows XP, Java 1.5
    • Number of attachments :
      0

      Description

      Memory mapped of NIO puts a lock on files on Windows. When Jetty sends a static file to a browser and an application subsequently tries to delete (replace that file), I get the following error message:

      Cause: java.io.FileNotFoundException: C:\Documents and Settings\george\My Documents\...\work\temp\temp.html (The requested operation cannot be performed on a file with a user-mapped section open)

      If I use the org.mortbay.jetty.bio.SocketConnector, then it works correctly (able to rewrite a static file). The problem only occurs with the NIO classes: org.mortbay.jetty.nio.SelectChannelConnector and org.mortbay.jetty.nio.BlockingChannelConnector.

      Maybe this is one of those inescapable design tradeoffs of NIO. If so, then it should be documented.

        Activity

        Hide
        Valerio Schiavoni added a comment -

        Same error from today snapshot build, most probably beta16.

        Show
        Valerio Schiavoni added a comment - Same error from today snapshot build, most probably beta16.
        Hide
        Jan Bartel added a comment -

        Sun say that they are not going to fix this issue:

        http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154

        Show
        Jan Bartel added a comment - Sun say that they are not going to fix this issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154
        Hide
        Jan Bartel added a comment -

        Actually, as I understand it, when the bytebuffer is garbage collected, then windows will free the file up. However, as the DefaultServlet, which serves static content, is caching content in memory, I suppose the bytebuffer will not be garbage collected until the entry is kicked out of the cache, which might never happen.

        Show
        Jan Bartel added a comment - Actually, as I understand it, when the bytebuffer is garbage collected, then windows will free the file up. However, as the DefaultServlet, which serves static content, is caching content in memory, I suppose the bytebuffer will not be garbage collected until the entry is kicked out of the cache, which might never happen.
        Hide
        Jan Bartel added a comment -

        The solution will be to use Direct buffer and copy the contents of the file into it and not keep the memory mapped buffer around. This will be a configuration option on DefaultServlet.

        Show
        Jan Bartel added a comment - The solution will be to use Direct buffer and copy the contents of the file into it and not keep the memory mapped buffer around. This will be a configuration option on DefaultServlet.
        Hide
        Jan Bartel added a comment -

        Fix checked in. Please see wiki entry: http://docs.codehaus.org/display/JETTY/Files+locked+on+Windows
        for information on how to configure.

        Show
        Jan Bartel added a comment - Fix checked in. Please see wiki entry: http://docs.codehaus.org/display/JETTY/Files+locked+on+Windows for information on how to configure.
        Hide
        Michael Waluk added a comment -

        The instructions on the wiki - using the new useFileMappedBuffer configuration point on DefaultServlet - probably works for WebAppContexts, but it doesn't seem to work for simple Contexts. I thought that since DefaultServlet was serving static content that it would. I'm using Jetty to host my Maven-generated site (static content) and in order to site:deploy updated files over the old ones we have to use org.mortbay.jetty.bio.SocketConnector instead of the NIO connectors in our version of jetty.xml.

        That is pretty obvious from the comments here and in the config file, but I thought this comment might help some other new users to use Jetty this way on Windows.

        Show
        Michael Waluk added a comment - The instructions on the wiki - using the new useFileMappedBuffer configuration point on DefaultServlet - probably works for WebAppContexts, but it doesn't seem to work for simple Contexts. I thought that since DefaultServlet was serving static content that it would. I'm using Jetty to host my Maven-generated site (static content) and in order to site:deploy updated files over the old ones we have to use org.mortbay.jetty.bio.SocketConnector instead of the NIO connectors in our version of jetty.xml. That is pretty obvious from the comments here and in the config file, but I thought this comment might help some other new users to use Jetty this way on Windows.

          People

          • Assignee:
            Jan Bartel
            Reporter:
            George Van Treeck
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: