You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Nourredine K. (JIRA)" <ji...@apache.org> on 2011/09/21 14:59:09 UTC

[jira] [Created] (TAP5-1660) Per-thread scope services not thread-safe

Per-thread scope services not thread-safe
-----------------------------------------

                 Key: TAP5-1660
                 URL: https://issues.apache.org/jira/browse/TAP5-1660
             Project: Tapestry 5
          Issue Type: Bug
          Components: tapestry-ioc
    Affects Versions: 5.2.5
            Reporter: Nourredine K.


Hi,

Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).

The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
That leads to strange behaviour when you use the Environmental services as data's container for example.

I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.

The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html

Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. closed TAP5-1660.
-------------------------------


> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. updated TAP5-1660:
--------------------------------

    Attachment: Perthread_scope_Threadsafe_Tapestry5.2.6.patch

Added a patch for Tapestry 5.2.6.

It fixes the issue highlighted in the sample.

Nourredine.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. resolved TAP5-1660.
---------------------------------

    Resolution: Invalid

Martin,

After more digging on the code, I think also that the threadLocal variable is enough and garantees the "thread-safe" aspect.The conditioned lock around the holder had misled me (PerthreadManagerImpl). Sorry for the false alarm and thanks for sharing with me such useful thoughts. 

Nourredine.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. updated TAP5-1660:
--------------------------------

    Attachment: tapestry5-concurrency-sample.zip

To illustrate the issue, check this simple project based on Tapestry 5.2.6 maven archetype. 

Run the maven tests. It will launch several threads in parallel. Also, you'll find more details in AppModule's comments. 

Nourredine.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Martin Strand (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109572#comment-13109572 ] 

Martin Strand commented on TAP5-1660:
-------------------------------------

This does not look like a bug.
The test checks whether the hashCodes of service objects are unique, which they don't need to be.
If you log the hashCode from the PageRenderQueueImpl constructor (in your example) you will see that distinct objects may have the same hashCode.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Martin Strand (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109693#comment-13109693 ] 

Martin Strand commented on TAP5-1660:
-------------------------------------

What about the proposed patch, is that still needed? It looks as if the locking in that patch is not necessary, since this concerns a PerThreadValue.
The concerned lines in PerThreadServiceCreator would typically be a race bug:

if (perThreadValue.exists())
  return perThreadValue.get();
return perThreadValue.set(delegate.createObject());

but since the only mutable object involved here is in a ThreadLocal (the Map in PerthreadManagerImpl#holder) I don't think there is any room for a race condition here, even without locking. Still, I have very little experience with this (just finished reading JCIP) and am just thinking out loud... What do you think? Are you able to demonstrate a problem with the current code?

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Martin Strand (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109572#comment-13109572 ] 

Martin Strand commented on TAP5-1660:
-------------------------------------

This does not look like a bug.
The test checks whether the hashCodes of service objects are unique, which they don't need to be.
If you log the hashCode from the PageRenderQueueImpl constructor (in your example) you will see that distinct objects may have the same hashCode.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. closed TAP5-1660.
-------------------------------


> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Martin Strand (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109693#comment-13109693 ] 

Martin Strand commented on TAP5-1660:
-------------------------------------

What about the proposed patch, is that still needed? It looks as if the locking in that patch is not necessary, since this concerns a PerThreadValue.
The concerned lines in PerThreadServiceCreator would typically be a race bug:

if (perThreadValue.exists())
  return perThreadValue.get();
return perThreadValue.set(delegate.createObject());

but since the only mutable object involved here is in a ThreadLocal (the Map in PerthreadManagerImpl#holder) I don't think there is any room for a race condition here, even without locking. Still, I have very little experience with this (just finished reading JCIP) and am just thinking out loud... What do you think? Are you able to demonstrate a problem with the current code?

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. updated TAP5-1660:
--------------------------------

    Attachment: Perthread_scope_Threadsafe_Tapestry5.2.6.patch

Added a patch for Tapestry 5.2.6.

It fixes the issue highlighted in the sample.

Nourredine.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109644#comment-13109644 ] 

Nourredine K. commented on TAP5-1660:
-------------------------------------

Martin,

You're right. I updated my sample to use a "true" unique id to identify my objects (InternalUtils.nextUUID(), thanks Howard :)) and all the tests pass!  

There is still an issue about PerthreadManager where some synchronization locks are dependent on the use of a specific jdk (1.5) 

See :

- PerthreadManagerImpl (lines 54 and 61) : http://svn.apache.org/viewvc/tapestry/tapestry5/tags/releases/5.2.6/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java?view=markup
- JDKUtils : http://svn.apache.org/viewvc/tapestry/tapestry5/tags/releases/5.2.6/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/JDKUtils.java?view=markup



> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. updated TAP5-1660:
--------------------------------

    Attachment: tapestry5-concurrency-sample.zip

To illustrate the issue, check this simple project based on Tapestry 5.2.6 maven archetype. 

Run the maven tests. It will launch several threads in parallel. Also, you'll find more details in AppModule's comments. 

Nourredine.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109644#comment-13109644 ] 

Nourredine K. commented on TAP5-1660:
-------------------------------------

Martin,

You're right. I updated my sample to use a "true" unique id to identify my objects (InternalUtils.nextUUID(), thanks Howard :)) and all the tests pass!  

There is still an issue about PerthreadManager where some synchronization locks are dependent on the use of a specific jdk (1.5) 

See :

- PerthreadManagerImpl (lines 54 and 61) : http://svn.apache.org/viewvc/tapestry/tapestry5/tags/releases/5.2.6/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java?view=markup
- JDKUtils : http://svn.apache.org/viewvc/tapestry/tapestry5/tags/releases/5.2.6/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/JDKUtils.java?view=markup



> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (TAP5-1660) Per-thread scope services not thread-safe

Posted by "Nourredine K. (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/TAP5-1660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nourredine K. resolved TAP5-1660.
---------------------------------

    Resolution: Invalid

Martin,

After more digging on the code, I think also that the threadLocal variable is enough and garantees the "thread-safe" aspect.The conditioned lock around the holder had misled me (PerthreadManagerImpl). Sorry for the false alarm and thanks for sharing with me such useful thoughts. 

Nourredine.

> Per-thread scope services not thread-safe
> -----------------------------------------
>
>                 Key: TAP5-1660
>                 URL: https://issues.apache.org/jira/browse/TAP5-1660
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-ioc
>    Affects Versions: 5.2.5
>            Reporter: Nourredine K.
>              Labels: ioc, jdk1.5, perthread, thread-safe
>         Attachments: Perthread_scope_Threadsafe_Tapestry5.2.6.patch, tapestry5-concurrency-sample.zip
>
>
> Hi,
> Since Tapestry 5.2, it seems that per-thread scope services are not thread-safe (some of our integration tests executed in parallel fail since Tapestry 5.2).
> The proxy managed by Tapestry does not create a new instance of the service for each request/thread as expected.
> That leads to strange behaviour when you use the Environmental services as data's container for example.
> I also noticed that the synchronization of some resources (used by per-thread scope services) is effective only for jdk 1.5 (see PerthreadmanagerImpl's constructor and JDUtils.JDK_1_5). But this aspect does not explain everything : the tests fail with JDK 1.5 too.
> The related discussion here : http://tapestry.1045711.n5.nabble.com/Tapestry-5-2-Per-thread-scope-services-not-thread-safe-td4825735.html
> Nourredine. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira