池 LdapTemplate 在上下文验证期间会停止几分钟



我正在尝试使用 Spring-ldap 的 LdapTemplate 在 Rest 调用服务实现期间从 LDAP 源检索信息,虽然我认为我有一个工作配置,但我们注意到当服务被击中时,间歇性地停滞长达 15 分钟。 日志记录语句已确定在ldapTemplate.search()调用期间发生停顿。

我的豆子:

contextSourceTarget(org.springframework.ldap.core.support.LdapContextSource) {
urls = ["https://someldapsource.com"]
userDn = 'uid=someaccount,ou=xxx,cn=users,dc=org,dc=com'
password = 'somepassword'
pooled = true
}
dirContextValidator(org.springframework.ldap.pool2.validation.DefaultDirContextValidator)
poolConfig( org.springframework.ldap.pool2.factory.PoolConfig ) {
testOnBorrow = true
testWhileIdle = true
}
ldapContextSource(org.springframework.ldap.pool2.factory.PooledContextSource, ref('poolConfig')) {
contextSource = ref('contextSourceTarget')
dirContextValidator = ref('dirContextValidator')
}
ldapTemplate(LdapTemplate, ref('ldapContextSource')) {}

我希望此应用程序可以同时多次点击LDAP(通过对此应用程序的并发休息调用(以从不同用户检索数据。 下面是进行该调用的代码:

List attrs =['uid', 'otherattr1', 'otherattr2']
// this just returns a Map containing the key value pairs of the attrs passed in here.
LdapNamedContextMapper mapper = new LdapNamedContextMapper( attrs ) 
log.debug( "getLdapUser:preLdapSearch")
List<Map> results = ldapTemplate.search( 
'cn=grouproot,cn=Groups,dc=org,dc=com',
'uniquemember=userNameImsearchingfor',
SearchControls.SUBTREE_SCOPE, 
attrs as String[], mapper )
log.debug( "getLdapUser:postLdapSearch" )

不幸的是,在随机时间,preLdapSearch和postLdapSearch日志之间的时间戳差异似乎超过15分钟。 显然,这很糟糕,这似乎是一个池管理问题。

所以我为包org.springframework.ldap和org.apache.commons.pool2打开了调试日志记录

。现在,当发生这种情况时,我在日志中得到以下内容:

2018-09-20 20:18:46.251 DEBUG appEvent="getLdapUser:preLdapSearch"
2018-09-20 20:35:03.246 DEBUG  A class javax.naming.ServiceUnavailableException - not explicitly configured to be a non-transient exception - encountered; ignoring.
2018-09-20 20:35:03.249 DEBUG  DirContext 'javax.naming.ldap.InitialLdapContext@1f4f37b4' failed validation with an exception.
javax.naming.ServiceUnavailableException: my.ldaphost.com:636; socket closed
at com.sun.jndi.ldap.Connection.readReply(Connection.java:454)
at com.sun.jndi.ldap.LdapClient.getSearchReply(LdapClient.java:638)
at com.sun.jndi.ldap.LdapClient.getSearchReply(LdapClient.java:638)
at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:561)
at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1985)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1844)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
(LOTS OF STACK TRACE REMOVED)
2018-09-20 20:35:03.249 DEBUG Closing READ_ONLY DirContext='javax.naming.ldap.InitialLdapContext@1f4f37b4'
2018-09-20 20:35:03.249 DEBUG Closed READ_ONLY DirContext='javax.naming.ldap.InitialLdapContext@1f4f37b4'
2018-09-20 20:35:03.249 DEBUG Creating a new READ_ONLY DirContext
2018-09-20 20:35:03.787 DEBUG Created new READ_ONLY DirContext='javax.naming.ldap.InitialLdapContext@5239386d'
2018-09-20 20:35:03.838 DEBUG DirContext 'javax.naming.ldap.InitialLdapContext@5239386d' passed validation.
2018-09-20 20:35:03.890 DEBUG appEvent="getLdapUser:postLdapSearch"

问题:

  1. 我怎样才能找到更多信息? 我已经为 org.springframework.ldap 和 org.apache.commons.pool2 打开了调试日志记录

  2. 为什么似乎需要 15+分钟才能确定连接过时/不可用? 如何配置以缩短它?

底层 LDAP 系统很有可能存在连接问题。 您可以尝试在连接池设置中添加超时:

max-wait - 默认值为 -1
逐出-运行-间隔-米利斯 - 你可以 想要设置此选项以控制检查问题的频率

文档:https://docs.spring.io/spring-ldap/docs/current/reference/#pool-configuration

最新更新