Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: V3
    • Fix Version/s: 3.1_b03
    • Component/s: web_container
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Linux

    • Issuezilla Id:
      11,979

      Description

      The API for javax.servlet.Filter.init() states:

      "The servlet container calls the init method exactly once after instantiating
      the filter."

      This is not true in Glassfish v3, apparently due to insufficient synchronization.

      A long running init() method may be called again by a different thread, which
      breaks any application relying on the contract defined in the API.

      To reproduce this behaviour, build a trivial web app named "filter" containing
      just the following class:

      @WebFilter(filterName="myFilter", urlPatterns="/*")
      public class MyFilter implements Filter {

      public void destroy() {
      }

      public void doFilter(ServletRequest arg0, ServletResponse arg1,
      FilterChain arg2) throws IOException, ServletException {
      }

      public void init(FilterConfig arg0) throws ServletException {
      String msg = String.format("MyFilter.init(), instance=%s, thread=%s, ",
      this, Thread.currentThread().getName());
      System.out.println(msg);
      try

      { Thread.sleep(2000); }

      catch (InterruptedException e)

      { e.printStackTrace(); }

      }
      }

      Then open 2 browser tabs on "http://localhost:8080/filter/foo" and
      "http://localhost:8080/filter/bar" in rapid succession.

      In the server log, you'll see

      MyFilter.init(), instance=com.example.MyFilter@31e956bd,
      thread=http-thread-pool-8088-(2),
      MyFilter.init(), instance=com.example.MyFilter@31e956bd,
      thread=http-thread-pool-8088-(1),

      i.e. the Filter was instantiated once, but the init() method was called twice by
      two diffrent threads.

        Activity

        Hide
        Shing Wai Chan added a comment -

        A synchronization issue is identified in the code.

        Show
        Shing Wai Chan added a comment - A synchronization issue is identified in the code.
        Hide
        Shing Wai Chan added a comment -

        Sending ApplicationFilterConfig.java
        Transmitting file data .
        Committed revision 37275.

        Show
        Shing Wai Chan added a comment - Sending ApplicationFilterConfig.java Transmitting file data . Committed revision 37275.

          People

          • Assignee:
            Shing Wai Chan
            Reporter:
            Harald Wellmann
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: