gpt4 book ai didi

grails - 合并的LdapTemplate在上下文验证期间停顿了几分钟

转载 作者:行者123 更新时间:2023-12-02 14:39:24 25 4
gpt4 key购买 nike

我正在尝试使用Spring-ldap的LdapTemplate在Rest调用服务实现期间从LDAP源中检索信息,尽管我认为我的配置正常,但是当服务被命中时,我们会间歇地等待15分钟。日志记录语句确定停顿发生在ldapTemplate.search()调用期间。

我的 bean :

    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"

问题:
  • 我如何找到更多?我已经为org.springframework.ldap和org.apache.commons.pool2
  • 打开了调试日志记录
  • 为什么似乎需要15分钟以上才能确定连接陈旧/不可用?我该如何配置以使其更短?
  • 最佳答案

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

    max-wait - default is -1
    eviction-run-interval-millis - you may want to set this to control how often to check for problems



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

    关于grails - 合并的LdapTemplate在上下文验证期间停顿了几分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52433937/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com