Weld
  1. Weld
  2. WELD-1020

NPE during cleanup after Servlet API3 AsyncContect

    Details

    • Steps to Reproduce:
      Hide

      The following example servlet demonstrates the problem. When accessing this servlet, there will be a NPE on the console/cataling log:
      java.lang.NullPointerException
      at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:71)
      at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:86)
      at org.jboss.weld.servlet.WeldListener.requestDestroyed(WeldListener.java:103)
      at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:42)
      at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:5973)
      at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:283)
      at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1515)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:523)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1575)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)

      An example servlet:

      package com.kobil.ssms.asm.presentation.b2b;

      import java.io.IOException;

      import javax.servlet.AsyncContext;
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      @WebServlet(asyncSupported = true, urlPatterns = "/weldasync")
      public class WeldAsyncServlet extends HttpServlet {

      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

      { doPost(request, response); }

      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
      IOException {
      final AsyncContext async = request.startAsync(request, response);
      Runnable asyncRunnable = new Runnable() {

      @Override
      public void run()

      { async.complete(); }

      };
      async.start(asyncRunnable);
      }

      }

      Show
      The following example servlet demonstrates the problem. When accessing this servlet, there will be a NPE on the console/cataling log: java.lang.NullPointerException at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:71) at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:86) at org.jboss.weld.servlet.WeldListener.requestDestroyed(WeldListener.java:103) at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:42) at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:5973) at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:283) at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1515) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:523) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1575) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) An example servlet: package com.kobil.ssms.asm.presentation.b2b; import java.io.IOException; import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(asyncSupported = true, urlPatterns = "/weldasync") public class WeldAsyncServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final AsyncContext async = request.startAsync(request, response); Runnable asyncRunnable = new Runnable() { @Override public void run() { async.complete(); } }; async.start(asyncRunnable); } }
    • Similar Issues:
      Show 10 results 

      Description

      When using Weld with Servlet API3.0 AsyncContext, there will be a NullPointerException, when Weld tries to cleanup the request.
      There seems to be a problem when asyncContext.complete() is called in a thread that was not the original thread that received the request

      example for the exception:

      java.lang.NullPointerException
      at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:71)
      at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:86)
      at org.jboss.weld.servlet.WeldListener.requestDestroyed(WeldListener.java:103)
      at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:42)
      at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:5973)
      at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:283)
      at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1515)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:523)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1575)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)

        Issue Links

          Activity

          Hide
          Denis Balazuc
          added a comment -

          We are using JBoss AS 7.1 (with Weld 1.5) and a portal application. We experience the same NPE in every portlet that make use of some Spring context, interestingly enough.

          As for the assumptions about doing cross-context includes and asynch servlets, I suppose both conditions are easily met within a portal environment.

          Now, using JBoss AS 7.1, there doesn't seem to be any workaround to this issue. Is there a possibility to create a patch, or is it safe enough to switch the Weld implementation to 2.0.2 which I believe fixes this issue?

          Many thanks

          Show
          Denis Balazuc
          added a comment - We are using JBoss AS 7.1 (with Weld 1.5) and a portal application. We experience the same NPE in every portlet that make use of some Spring context, interestingly enough. As for the assumptions about doing cross-context includes and asynch servlets, I suppose both conditions are easily met within a portal environment. Now, using JBoss AS 7.1, there doesn't seem to be any workaround to this issue. Is there a possibility to create a patch, or is it safe enough to switch the Weld implementation to 2.0.2 which I believe fixes this issue? Many thanks
          Hide
          Jozef Hartinger
          added a comment -

          There is not easy way to use Weld 2.0 with AS 7.1. Try upgrading to WildFly 8.

          Show
          Jozef Hartinger
          added a comment - There is not easy way to use Weld 2.0 with AS 7.1. Try upgrading to WildFly 8.
          Hide
          Chris Rankin
          added a comment - - edited

          You say that this issue has been fixed in WELD 2.0.0.Beta7? However, I have just tested the sample Async Servlet (above) against WELD 2.1.1.Final (and Tomcat 7.0.23), and have created the following stack dump:

          2014-02-04 15:27:28,508 [http-apr-8080-exec-8] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/]- Exception sending request initialized lifecycle event to listener instance of class org.jboss.weld.environment.servlet.Listener
          java.lang.NullPointerException
          	at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:71)
          	at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:70)
          	at org.jboss.weld.servlet.HttpContextLifecycle.requestDestroyed(HttpContextLifecycle.java:225)
          	at org.jboss.weld.servlet.WeldInitialListener.requestDestroyed(WeldInitialListener.java:118)
          	at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:38)
          	at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:5973)
          	at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:283)
          	at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1515)
          	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:523)
          	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1817)
          	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
          	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
          	at java.lang.Thread.run(Thread.java:744)
          

          Have I missed something, please?

          Show
          Chris Rankin
          added a comment - - edited You say that this issue has been fixed in WELD 2.0.0.Beta7? However, I have just tested the sample Async Servlet (above) against WELD 2.1.1.Final (and Tomcat 7.0.23), and have created the following stack dump: 2014-02-04 15:27:28,508 [http-apr-8080-exec-8] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/]- Exception sending request initialized lifecycle event to listener instance of class org.jboss.weld.environment.servlet.Listener java.lang.NullPointerException at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:71) at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:70) at org.jboss.weld.servlet.HttpContextLifecycle.requestDestroyed(HttpContextLifecycle.java:225) at org.jboss.weld.servlet.WeldInitialListener.requestDestroyed(WeldInitialListener.java:118) at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:38) at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:5973) at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:283) at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1515) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:523) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1817) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang. Thread .run( Thread .java:744) Have I missed something, please?
          Hide
          Martin Kouba
          added a comment -

          There are still other issues with async servlets and also form-based authentication (https://community.jboss.org/thread/232194). Please post a question to community forum and describe your application or provide a simple reproducer.

          Show
          Martin Kouba
          added a comment - There are still other issues with async servlets and also form-based authentication ( https://community.jboss.org/thread/232194 ). Please post a question to community forum and describe your application or provide a simple reproducer.
          Hide
          Jozef Hartinger
          added a comment -

          Filed WELD-1598 to track the Tomcat issue.

          Show
          Jozef Hartinger
          added a comment - Filed WELD-1598 to track the Tomcat issue.

            People

            • Assignee:
              Martin Kouba
              Reporter:
              Manuel Hartl
            • Votes:
              2 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: