You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by "Supun Kamburugamuva (JIRA)" <ji...@apache.org> on 2009/11/09 07:34:32 UTC
[jira] Created: (SYNAPSE-595) Possible race condition in
ConnectionPool implementation of nhhtp transport
Possible race condition in ConnectionPool implementation of nhhtp transport
---------------------------------------------------------------------------
Key: SYNAPSE-595
URL: https://issues.apache.org/jira/browse/SYNAPSE-595
Project: Synapse
Issue Type: Bug
Components: Transports
Reporter: Supun Kamburugamuva
The nhttp transport connection pool uses double checked locking when it releases a connection. But double checked locking is not a recommended practice in Java and its use is avoided. Simply because it is not working.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org
[jira] Resolved: (SYNAPSE-595) Possible race condition in
ConnectionPool implementation of nhhtp transport
Posted by "Asankha C. Perera (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SYNAPSE-595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Asankha C. Perera resolved SYNAPSE-595.
---------------------------------------
Resolution: Invalid
Assignee: Asankha C. Perera
Supun
The reason why double checked locking typically fails for the singleton pattern implementation is because the Java memory model allows a thread to observe a lazily constructed object in a partially initialized state on possibly multi CPU/core systems. This is well described by Joshua Bloch in Effective Java - item # 48. It is not the case here, and connMap is a Synchronized Map, so the "List connections = (List) connMap.get(key);" will *always* get the latest valid object.
So as far as I see, this JIRA should not be categorized as a "major" "bug" and thus your code patch does not "fix" anything, except for always re-entering the same object twice for every single connection return.
- List connections = (List) connMap.get(key);
- if (connections == null) {
- synchronized(connMap) {
- // use double locking to make sure
- connections = (List) connMap.get(key);
- if (connections == null) {
- connections = Collections.synchronizedList(new LinkedList());
- connMap.put(key, connections);
- }
+ List connections;
+ synchronized(connMap) {
+ connections = (List) connMap.get(key);
+ if (connections == null) {
+ connections = Collections.synchronizedList(new LinkedList());
+ connMap.put(key, connections);
Ofcourse this class could still be improved, esp with some new features of the JDK, but its better done as an enhancement and including other overall improvements.
asankha
> Possible race condition in ConnectionPool implementation of nhhtp transport
> ---------------------------------------------------------------------------
>
> Key: SYNAPSE-595
> URL: https://issues.apache.org/jira/browse/SYNAPSE-595
> Project: Synapse
> Issue Type: Bug
> Components: Transports
> Reporter: Supun Kamburugamuva
> Assignee: Asankha C. Perera
> Attachments: SYNAPSE-595.patch
>
>
> The nhttp transport connection pool uses double checked locking when it releases a connection. But double checked locking is not a recommended practice in Java and its use is avoided. Simply because it is not working.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org
[jira] Updated: (SYNAPSE-595) Possible race condition in
ConnectionPool implementation of nhhtp transport
Posted by "Supun Kamburugamuva (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SYNAPSE-595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Supun Kamburugamuva updated SYNAPSE-595:
----------------------------------------
Attachment: SYNAPSE-595.patch
Attaching a patch that removes the double check locking.
Here is a document that describes why double checked locking doesn't work in java.
http://www.ibm.com/developerworks/java/library/j-dcl.html
> Possible race condition in ConnectionPool implementation of nhhtp transport
> ---------------------------------------------------------------------------
>
> Key: SYNAPSE-595
> URL: https://issues.apache.org/jira/browse/SYNAPSE-595
> Project: Synapse
> Issue Type: Bug
> Components: Transports
> Reporter: Supun Kamburugamuva
> Attachments: SYNAPSE-595.patch
>
>
> The nhttp transport connection pool uses double checked locking when it releases a connection. But double checked locking is not a recommended practice in Java and its use is avoided. Simply because it is not working.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org
[jira] Commented: (SYNAPSE-595) Possible race condition in
ConnectionPool implementation of nhhtp transport
Posted by "Supun Kamburugamuva (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SYNAPSE-595?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12775112#action_12775112 ]
Supun Kamburugamuva commented on SYNAPSE-595:
---------------------------------------------
HI Asanka,
I agree with you.
Thanks,
Supun..
> Possible race condition in ConnectionPool implementation of nhhtp transport
> ---------------------------------------------------------------------------
>
> Key: SYNAPSE-595
> URL: https://issues.apache.org/jira/browse/SYNAPSE-595
> Project: Synapse
> Issue Type: Bug
> Components: Transports
> Reporter: Supun Kamburugamuva
> Assignee: Asankha C. Perera
> Attachments: SYNAPSE-595.patch
>
>
> The nhttp transport connection pool uses double checked locking when it releases a connection. But double checked locking is not a recommended practice in Java and its use is avoided. Simply because it is not working.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org