You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Christopher Hunt (JIRA)" <ji...@apache.org> on 2009/05/02 12:21:38 UTC

[jira] Created: (CAMEL-1583) ldap component is not thread safe

ldap component is not thread safe
---------------------------------

                 Key: CAMEL-1583
                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
             Project: Apache Camel
          Issue Type: Bug
          Components: camel-ldap
    Affects Versions: 2.0-M1, 1.6.0
         Environment: N/A
            Reporter: Christopher Hunt


JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.

In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.

JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:

{code}
ctx = new InitialDirContext(env);
try {
  ...
} finally {
  ctx.close();
}
{code}

The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-1583) ldap component is not thread safe

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=51503#action_51503 ] 

Claus Ibsen commented on CAMEL-1583:
------------------------------------

Christopher.

Thanks again for doing the patch and the investigations. And provided yet another patch.

> ldap component is not thread safe
> ---------------------------------
>
>                 Key: CAMEL-1583
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-ldap
>    Affects Versions: 1.6.0, 2.0-M1
>         Environment: N/A
>            Reporter: Christopher Hunt
>            Assignee: Claus Ibsen
>             Fix For: 1.6.1, 2.0.0
>
>         Attachments: LdapProducer.java.diff
>
>
> JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.
> In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.
> JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:
> {code}
> ctx = new InitialDirContext(env);
> try {
>   ...
> } finally {
>   ctx.close();
> }
> {code}
> The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAMEL-1583) ldap component is not thread safe

Posted by "Christopher Hunt (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christopher Hunt updated CAMEL-1583:
------------------------------------

    Attachment: LdapProducer.java.diff

Changes to the 1.6.1 branch.

In essence a context is retrieved from the registry each time that an exchange is to be produced.

Given that the contract for an InitialContext states:

_An InitialContext instance is not synchronized against concurrent access by multiple threads. Multiple threads each manipulating a different InitialContext instance need not synchronize. Threads that need to access a single InitialContext instance concurrently should synchronize amongst themselves and provide the necessary locking._

The registry entry should either: (a) provide an InitialContext that is known to be thread safe; or (b) ensure that the registry instantiates a new bean each time that the bean is looked up. The latter will be the general situation and so, for example with Spring IOC, use a bean declaration similar to:

{code}
	<!-- Directory Context -->
	<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
		<constructor-arg>
			<props>
				<prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
				<prop key="java.naming.provider.url">ldap://localhost:10389</prop>
				<prop key="java.naming.security.authentication">none</prop>
			</props>
		</constructor-arg>
	</bean>
{code}

It is important to use a prototype scope to ensure that a new directory context is obtained for each exchange produced.

> ldap component is not thread safe
> ---------------------------------
>
>                 Key: CAMEL-1583
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-ldap
>    Affects Versions: 1.6.0, 2.0-M1
>         Environment: N/A
>            Reporter: Christopher Hunt
>         Attachments: LdapProducer.java.diff
>
>
> JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.
> In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.
> JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:
> {code}
> ctx = new InitialDirContext(env);
> try {
>   ...
> } finally {
>   ctx.close();
> }
> {code}
> The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (CAMEL-1583) ldap component is not thread safe

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned CAMEL-1583:
----------------------------------

    Assignee: Claus Ibsen

> ldap component is not thread safe
> ---------------------------------
>
>                 Key: CAMEL-1583
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-ldap
>    Affects Versions: 1.6.0, 2.0-M1
>         Environment: N/A
>            Reporter: Christopher Hunt
>            Assignee: Claus Ibsen
>         Attachments: LdapProducer.java.diff
>
>
> JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.
> In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.
> JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:
> {code}
> ctx = new InitialDirContext(env);
> try {
>   ...
> } finally {
>   ctx.close();
> }
> {code}
> The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CAMEL-1583) ldap component is not thread safe

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-1583.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0.0
                   1.6.1

trunk: 771303, 771307.
1.x: 771309.

Yeah I needed two commits on trunk as the patch was for 1.x and it used generics in the LdapProducer. So I had to remove it again on trunk :)

> ldap component is not thread safe
> ---------------------------------
>
>                 Key: CAMEL-1583
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-ldap
>    Affects Versions: 1.6.0, 2.0-M1
>         Environment: N/A
>            Reporter: Christopher Hunt
>            Assignee: Claus Ibsen
>             Fix For: 1.6.1, 2.0.0
>
>         Attachments: LdapProducer.java.diff
>
>
> JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.
> In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.
> JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:
> {code}
> ctx = new InitialDirContext(env);
> try {
>   ...
> } finally {
>   ctx.close();
> }
> {code}
> The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAMEL-1583) ldap component is not thread safe

Posted by "Christopher Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=51494#action_51494 ] 

Christopher Hunt commented on CAMEL-1583:
-----------------------------------------

I forgot to mention that I ran the ldap unit tests and all was well. In addition I used the modified class within my application and confiirmed (using the debugger) that a new context instance was being used each time.

> ldap component is not thread safe
> ---------------------------------
>
>                 Key: CAMEL-1583
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-ldap
>    Affects Versions: 1.6.0, 2.0-M1
>         Environment: N/A
>            Reporter: Christopher Hunt
>         Attachments: LdapProducer.java.diff
>
>
> JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.
> In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.
> JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:
> {code}
> ctx = new InitialDirContext(env);
> try {
>   ...
> } finally {
>   ctx.close();
> }
> {code}
> The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAMEL-1583) ldap component is not thread safe

Posted by "Christopher Hunt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=51493#action_51493 ] 

Christopher Hunt edited comment on CAMEL-1583 at 5/4/09 1:56 AM:
-----------------------------------------------------------------

Changes to the 1.6.1 branch.

In essence a context is retrieved from the registry each time that an exchange is to be produced.

Given that the contract for an InitialContext states:

_An InitialContext instance is not synchronized against concurrent access by multiple threads. Multiple threads each manipulating a different InitialContext instance need not synchronize. Threads that need to access a single InitialContext instance concurrently should synchronize amongst themselves and provide the necessary locking._

...the registry entry should either: (a) provide an InitialContext that is known to be thread safe; or (b) ensure that the registry instantiates a new bean each time that the bean is looked up. The latter will be the general situation and so, for example with Spring IOC, use a bean declaration similar to:

{code}
	<!-- Directory Context -->
	<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
		<constructor-arg>
			<props>
				<prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
				<prop key="java.naming.provider.url">ldap://localhost:10389</prop>
				<prop key="java.naming.security.authentication">none</prop>
			</props>
		</constructor-arg>
	</bean>
{code}

It is important to use a prototype scope to ensure that a new directory context is obtained for each exchange produced.

      was (Author: huntc@internode.on.net):
    Changes to the 1.6.1 branch.

In essence a context is retrieved from the registry each time that an exchange is to be produced.

Given that the contract for an InitialContext states:

_An InitialContext instance is not synchronized against concurrent access by multiple threads. Multiple threads each manipulating a different InitialContext instance need not synchronize. Threads that need to access a single InitialContext instance concurrently should synchronize amongst themselves and provide the necessary locking._

The registry entry should either: (a) provide an InitialContext that is known to be thread safe; or (b) ensure that the registry instantiates a new bean each time that the bean is looked up. The latter will be the general situation and so, for example with Spring IOC, use a bean declaration similar to:

{code}
	<!-- Directory Context -->
	<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
		<constructor-arg>
			<props>
				<prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
				<prop key="java.naming.provider.url">ldap://localhost:10389</prop>
				<prop key="java.naming.security.authentication">none</prop>
			</props>
		</constructor-arg>
	</bean>
{code}

It is important to use a prototype scope to ensure that a new directory context is obtained for each exchange produced.
  
> ldap component is not thread safe
> ---------------------------------
>
>                 Key: CAMEL-1583
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-1583
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-ldap
>    Affects Versions: 1.6.0, 2.0-M1
>         Environment: N/A
>            Reporter: Christopher Hunt
>         Attachments: LdapProducer.java.diff
>
>
> JNDI context objects are not thread-safe. The LDAP component shares a directory context across all threads that use the component. This is not safe.
> In addition the LDAP component will attempt to establish a connection on instantiation of the component, and not when the component is required to process requests. If the LDAP server is not ready e.g. temporarily unavailable then the entire Camel application will stop.
> JNDI directory contexts should be established when a consuming thread needs it and should be released when the thread is finished with the component i.e.:
> {code}
> ctx = new InitialDirContext(env);
> try {
>   ...
> } finally {
>   ctx.close();
> }
> {code}
> The above will release the connection with the LDAP server as soon as possible. The existing component relies on JNDI to release the socket in its own time (several seconds later).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.