You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Claudio Tasso (JIRA)" <de...@myfaces.apache.org> on 2006/02/19 14:39:24 UTC

[jira] Created: (MYFACES-1137) ExtensionsFilter is not THREAD SAFE

ExtensionsFilter is not THREAD SAFE
-----------------------------------

         Key: MYFACES-1137
         URL: http://issues.apache.org/jira/browse/MYFACES-1137
     Project: MyFaces
        Type: Bug
  Components: Tomahawk  
    Versions: Nightly    
 Environment: JDK 1.5, OC4J
    Reporter: Claudio Tasso
    Priority: Critical


Using Tomahawk I experimented some problems with the ExtensionFilter, in particular some errors occur when the MyFaces javascript is written inside the body of the response.
This is the typical error message:

java.lang.StringIndexOutOfBoundsException
   at java.lang.StringBuffer.insert(StringBuffer.java:905)
   at org.apache.myfaces.renderkit.html.util.DefaultAddResource.writeMyFacesJavascriptBeforeBodyEnd(DefaultAddResource.java:658)
   at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:138)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:699)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:397)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:833)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:430)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
   at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:215)
   at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
   at java.lang.Thread.run(Thread.java:534)

This error occurs randomly. Looking at the AddResourceFactory code, I see that only one AddResource instace exists and this instance is shared among  the servlet threads.
The ExtensionFilter calulates the beforeBodyEndPosition value  (which is a DefaultAddResource property) and then this value is used for writing inside a StringBuffer which should contain the response body.
This is the code in ExtensionFilter the I'm talking about:

addResource.parseResponse(extendedRequest, extendedResponse.toString(),
                   servletResponse);

addResource.writeMyFacesJavascriptBeforeBodyEnd(extendedRequest,
                   servletResponse);


The problem is that a typical race condition seems to happen.
The beforeBodyEndPosition value is calulated for Thread1, which is suspended. Then, Thread 2 starts and it modifies the beforeBodyEndPosition value. When Thread2 terminates, Thread1 resumes and it tries to write inside its body response at an index which is no more valid.

The reason of this behaviour is (according to me) the following: there is just one instance of DefaultAddResource,  so the execution of  AddResource.parseResponse and AddResource.writeMyFacesJavascriptBeforeBodyEnd should be atomic. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (TOMAHAWK-108) ExtensionsFilter is not THREAD SAFE

Posted by "Mario Ivankovits (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/TOMAHAWK-108?page=all ]
     
Mario Ivankovits closed TOMAHAWK-108:
-------------------------------------


> ExtensionsFilter is not THREAD SAFE
> -----------------------------------
>
>          Key: TOMAHAWK-108
>          URL: http://issues.apache.org/jira/browse/TOMAHAWK-108
>      Project: MyFaces Tomahawk
>         Type: Bug
>  Environment: JDK 1.5, OC4J
>     Reporter: Claudio Tasso
>     Assignee: Mario Ivankovits
>     Priority: Critical

>
> Using Tomahawk I experimented some problems with the ExtensionFilter, in particular some errors occur when the MyFaces javascript is written inside the body of the response.
> This is the typical error message:
> java.lang.StringIndexOutOfBoundsException
>    at java.lang.StringBuffer.insert(StringBuffer.java:905)
>    at org.apache.myfaces.renderkit.html.util.DefaultAddResource.writeMyFacesJavascriptBeforeBodyEnd(DefaultAddResource.java:658)
>    at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:138)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:699)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:397)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:833)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:430)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
>    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:215)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
>    at java.lang.Thread.run(Thread.java:534)
> This error occurs randomly. Looking at the AddResourceFactory code, I see that only one AddResource instace exists and this instance is shared among  the servlet threads.
> The ExtensionFilter calulates the beforeBodyEndPosition value  (which is a DefaultAddResource property) and then this value is used for writing inside a StringBuffer which should contain the response body.
> This is the code in ExtensionFilter the I'm talking about:
> addResource.parseResponse(extendedRequest, extendedResponse.toString(),
>                    servletResponse);
> addResource.writeMyFacesJavascriptBeforeBodyEnd(extendedRequest,
>                    servletResponse);
> The problem is that a typical race condition seems to happen.
> The beforeBodyEndPosition value is calulated for Thread1, which is suspended. Then, Thread 2 starts and it modifies the beforeBodyEndPosition value. When Thread2 terminates, Thread1 resumes and it tries to write inside its body response at an index which is no more valid.
> The reason of this behaviour is (according to me) the following: there is just one instance of DefaultAddResource,  so the execution of  AddResource.parseResponse and AddResource.writeMyFacesJavascriptBeforeBodyEnd should be atomic. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (TOMAHAWK-108) ExtensionsFilter is not THREAD SAFE

Posted by "Mario Ivankovits (JIRA)" <de...@myfaces.apache.org>.
     [ http://issues.apache.org/jira/browse/TOMAHAWK-108?page=all ]
     
Mario Ivankovits resolved TOMAHAWK-108:
---------------------------------------

    Resolution: Fixed

Made AddResource request scope so it is request safe now.
Its still not "thread safe" but this is not required as the request-thread is now the only thread accessing it.

> ExtensionsFilter is not THREAD SAFE
> -----------------------------------
>
>          Key: TOMAHAWK-108
>          URL: http://issues.apache.org/jira/browse/TOMAHAWK-108
>      Project: MyFaces Tomahawk
>         Type: Bug
>  Environment: JDK 1.5, OC4J
>     Reporter: Claudio Tasso
>     Assignee: Mario Ivankovits
>     Priority: Critical

>
> Using Tomahawk I experimented some problems with the ExtensionFilter, in particular some errors occur when the MyFaces javascript is written inside the body of the response.
> This is the typical error message:
> java.lang.StringIndexOutOfBoundsException
>    at java.lang.StringBuffer.insert(StringBuffer.java:905)
>    at org.apache.myfaces.renderkit.html.util.DefaultAddResource.writeMyFacesJavascriptBeforeBodyEnd(DefaultAddResource.java:658)
>    at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:138)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:699)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:397)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:833)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:430)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
>    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:215)
>    at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) - Developer Preview 4].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
>    at java.lang.Thread.run(Thread.java:534)
> This error occurs randomly. Looking at the AddResourceFactory code, I see that only one AddResource instace exists and this instance is shared among  the servlet threads.
> The ExtensionFilter calulates the beforeBodyEndPosition value  (which is a DefaultAddResource property) and then this value is used for writing inside a StringBuffer which should contain the response body.
> This is the code in ExtensionFilter the I'm talking about:
> addResource.parseResponse(extendedRequest, extendedResponse.toString(),
>                    servletResponse);
> addResource.writeMyFacesJavascriptBeforeBodyEnd(extendedRequest,
>                    servletResponse);
> The problem is that a typical race condition seems to happen.
> The beforeBodyEndPosition value is calulated for Thread1, which is suspended. Then, Thread 2 starts and it modifies the beforeBodyEndPosition value. When Thread2 terminates, Thread1 resumes and it tries to write inside its body response at an index which is no more valid.
> The reason of this behaviour is (according to me) the following: there is just one instance of DefaultAddResource,  so the execution of  AddResource.parseResponse and AddResource.writeMyFacesJavascriptBeforeBodyEnd should be atomic. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira