You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Giovanni Azua <gi...@imc.nl> on 2008/05/21 10:41:56 UTC

Re: S2 2.1.1 race condition passing request params: bug?

hi,

I found XWorkBasicConverter.java is making thread-unsafe use of the 
mutable Calendar and SimpleDateFormat singletons, this could explain the 
race-condition issue.

I am trying to debug it now ...

regards,
Giovanni

Giovanni Azua wrote:
> hi,
>
> I found in the S2 2.1.1 test build the following scenario that seems to
> be a bug, please confirm and I will enter a new ticket for it.
>
> I have a JSP page that allows the user to run simulations. This page
> includes among others two datetimepicker fields "beginDate" and "endDate".
>
> It is a requirement that the user should be allowed to open e.g. five
> firefox browser views and execute simultaneously five simulations. The
> problem is that if the user submits two simulations simultaneously
> enough the parameters of one request end up being assigned to the other
> request too meaning there is a race condition somewhere before the
> parameter gets assigned to the Action.
>
> Possible reasons for this:
>
> - a Stateful thread-unsafe interceptor
> - dojo?
>
> I would appreciate any directions on this.
>
> best regards,
> Giovanni
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: S2 2.1.1 race condition passing request params: bug?

Posted by Giovanni Azua <gi...@imc.nl>.
hi,

I double-checked and the statement below is not correct. 
Calendar.getInstance is thread-safe as it will return a different 
instance each time. Similarly DateFormat.getDateTimeInstance will return 
a different instance each time too. Sorry it was a lapsus-mentis :)

On the other hand, continuously creating Calendar and SimpleDateFormat 
instances is very costly performance-wise, depending on the calling 
counts it would be maybe worthwhile consider using ThreadLocal and have 
one Singleton instance per thread.

regards,
Giovanni
> I found XWorkBasicConverter.java is making thread-unsafe use of the
> mutable Calendar and SimpleDateFormat singletons, this could explain the
> race-condition issue.
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: [struts-dev] S2 2.1.1 race condition passing request params: bug?

Posted by Dale Newfield <Da...@Newfield.org>.
Giovanni Azua wrote:
> Hah!! I wish these restrictions would pop up on my face rather than 
> having to discover them in the hard way :)

http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html sez:
> This interceptor works on a per-session basis. That means that the 
> same action name (myLongRunningAction, in the above example) cannot
> be run more than once at a time in a given session.

Giovanni Azua wrote:
 > Could this restriction be overcome? maybe finding a way to pair the
 > requests, maybe using a request id in the Session ... can I make an
 > improvement request perhaps also work on it?

I'd suggest adding some sort of token that is handed back and forth from 
server to client to server in order to correlate requests and their 
corresponding threads.  Be very careful how you try to use the session 
here, though:

http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html sez:
 > Important: Because the action will be running in a seperate thread,
 > you can't use ActionContext because it is a ThreadLocal. This means
 > if you need to access, for example, session data, you need to
 > implement SessionAware rather than calling ActionContext.getSesion().

I looked into this last year at some point and found it was less trivial 
than I had hoped :-).  I don't currently have the time to dig in and fix 
it, but we would of course all appreciate someone trying to remove this 
limitation.

(Maybe if the token is not available it could display a "wait-list" page 
that lists links to the corresponding action's threads associated with 
the current session?)

Whether or not you can provide patches to fix this, it can't hurt to add 
a JIRA request detailing the issues involved.

Of course a workaround/hack you could use to sidestep this would be to 
replicate your action with different names...

I'm not sure exactly what the restriction is--maybe you can define a 
wildcarded action so that there are multiple available?
<action name="someAction-*" class="com.examples.SomeAction">
     <interceptor-ref name="completeStack"/>
     <interceptor-ref name="execAndWait"/>
     <result name="wait">longRunningAction-wait.jsp</result>
     <result name="success">longRunningAction-success.jsp</result>
</action>

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: [struts-dev] S2 2.1.1 race condition passing request params: bug?

Posted by Giovanni Azua <gi...@imc.nl>.
Hah!! I wish these restrictions would pop up on my face rather than 
having to discover them in the hard way :) 

Dale many thanks for the clarification! Could this restriction be 
overcome? maybe finding a way to pair the requests, maybe using a 
request id in the Session ... can I make an improvement request perhaps 
also work on it?

Best regards,
Giovanni

Dale Newfield wrote:
> Giovanni Azua wrote:
>   
>> The race-condition happens only because my simulation process uses the
>> execAndWait interceptor
>>     
>
> The execAndWait interceptor has a restriction that it can only support a
> single long running task per action name per session.  It is this
> restriction that allows follow-up requests to be paired with the
> appropriate long running task.
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: [struts-dev] S2 2.1.1 race condition passing request params: bug?

Posted by Dale Newfield <Da...@Newfield.org>.
Giovanni Azua wrote:
> The race-condition happens only because my simulation process uses the 
> execAndWait interceptor

The execAndWait interceptor has a restriction that it can only support a 
single long running task per action name per session.  It is this 
restriction that allows follow-up requests to be paired with the 
appropriate long running task.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: S2 2.1.1 race condition passing request params: bug?

Posted by Giovanni Azua <gi...@imc.nl>.
hi,

The race-condition happens only because my simulation process uses the 
execAndWait interceptor:

<action name="SimulationRun" 
class="com.sag.optimizer.ui.web.action.simulation.SimulationRunAction">
 <interceptor-ref name="defaultStack"/>
 <interceptor-ref name="execAndWait">
   <param name="delay">1000</param>
   <param name="delaySleepInterval">1000</param>
 </interceptor-ref>
 <result name="wait" type="tiles">webui.simulationWait</result>
 <result name="success" type="tiles">webui.simulationReport</result>
 <result name="input" type="tiles">${ type.equals('COVARIANT') ? 
'webui.formCovSimulation' : 'webui.formInvSimulation' }</result>
 <result name="error" type="tiles">webui.requestFailed</result>
</action>       

When I change and use the default stack then I can not reproduce the 
race-condition issue anymore.

I am entering a new ticket for this maybe also another one to review the 
code at risk of race conditions using Calendar.getInstance and 
SimpleDateFormat singletons.

regards,
Giovanni

Giovanni Azua wrote:
> hi,
>
> I found XWorkBasicConverter.java is making thread-unsafe use of the
> mutable Calendar and SimpleDateFormat singletons, this could explain the
> race-condition issue.
>
> I am trying to debug it now ...
>
> regards,
> Giovanni
>
> Giovanni Azua wrote:
>   
>> hi,
>>
>> I found in the S2 2.1.1 test build the following scenario that seems to
>> be a bug, please confirm and I will enter a new ticket for it.
>>
>> I have a JSP page that allows the user to run simulations. This page
>> includes among others two datetimepicker fields "beginDate" and "endDate".
>>
>> It is a requirement that the user should be allowed to open e.g. five
>> firefox browser views and execute simultaneously five simulations. The
>> problem is that if the user submits two simulations simultaneously
>> enough the parameters of one request end up being assigned to the other
>> request too meaning there is a race condition somewhere before the
>> parameter gets assigned to the Action.
>>
>> Possible reasons for this:
>>
>> - a Stateful thread-unsafe interceptor
>> - dojo?
>>
>> I would appreciate any directions on this.
>>
>> best regards,
>> Giovanni
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>> For additional commands, e-mail: dev-help@struts.apache.org
>>
>>
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org