The last day before the festival, SSO login problems, most users can not log in normally. After the query log, the error is as follows:
The error log is truncated as follows
2015-02-15 08:40:30,536 INFO [Org.jasig.cas.authentication.AuthenticationManagerImpl]-<com. Gaochao.Oa.module.sso.authentication.handler.FxLdapMixAuthenticationHandlersuccessfully authenticated[username:wei.guo]>
2015-02-15 08:40:30,536 INFO [Org.jasig.cas.authentication.AuthenticationManagerImpl]-<resolved Principal Wei.guo>
2015-02-15 08:40:30,536 INFO [Org.jasig.cas.authentication.AuthenticationManagerImpl]-<com. Gaochao.Oa.m[email PROTECTED]7952DDA7 authenticated Wei.guo with credential [username:wei.guo].>
2015-02-15 08:40:30,537 INFO [Com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager]-<audit Trail Record BEGIN
2015-02-15 08:40:30,576 ERROR [com. Gaochao.Oa.module.sso.ticket.registry.RedisTicketRegistry]-<failed adding tgt-18015-b0igjb5vgg03iivqxkl5vso0tnbtyipfauzcklcfd2mvhvytep-cas01.example.org, error message:Could not get a resource from the pool>
2015-02-15 08:40:30,576 INFO [Com.github.inspektr.audit.support.Slf4jLoggingAuditTrailManager]-<audit Trail Record BEGIN
2015-02-15 08:40:30,955 ERROR [com. Gaochao.Oa.module.sso.ticket.registry.RedisTicketRegistry]-<failed adding tgt-18016-nmazefsqrg393dcaner4s1tc2ff1wwdcafrngwesgxkwlkcfn3-cas01.example.org, error message:could not get a Resource from the pool>
The above log shows that the problem code is in SSO, and the Red Bold section shows that the SSO server certificate and user authentication are successful.
if (!authenticationhandler.authenticate (credentials)) {Log.info ("{} failed to authenticate {}", HandlerName, credentials);} else {Log.info ("{} successfully authenticated {}", handlername,credentials); Authenticatedclass = authenticationhandler;authenticated = True;break;}
But failed to generate authentication service credentials ticket and obtain resources
try {jedis = getresource ();byte[] b = Jedis.hget (Sso_hash_id, ticketid.getbytes ());if (b == null | | b.length == 0) {return null;} Bytearrayinputstream bais = new bytearrayinputstream (b);ois = new ObjectInputStream (Bais);ticket = (ticket) ois.readobject ();} catch (jedisexception e) {borroworoprsuccess = false;returnbrokenresource (Jedis ); Log.error ("failed getticket {}, error message :{}", ticketid,e.getmessage ());} catch (exception e) {log.error ("Failed getticket {}, error message :{} ", ticketid,e.getmessage ());}
could Not get a resource from the pool can be thought of as redis exception. Further tracking the location of the exception, see the following code:
@SuppressWarnings ("unchecked") public T getresource () {try {return (T) Internalpool.borrowobject ();} catch (Exception E {throw new Jedisconnectionexception ("Could not get a resource from the pool", e);}}
find information on the Internet, it is generally considered that this anomaly and Pool connection configuration for Redis about:
One of the possible reasons for the Red section is that when the client goes to the redis Server to get the connection (the code describes the leased object borrowobject), there is no connection available in the pool, that is, all connections in the pool are occupied , and this exception is reported when the timeout is not received after the wait time has been set .
Workaround:
1. Adjust the maxactive in the jedispoolconfig to suit your system, of course it is necessary to restart the service and connect the rebuild pool in this case.
when I view the redis configurationof our system, theredis.properties is configured as redis.maxidle=5000,
# Redis Settingsredis.maxidle=5000redis.maxactive=5000redis.maxwait=10000redis.testonborrow=true
5000 The concurrency is enough, there will be no access to resources, but our system has appeared, continue to check the data found that the cause of this problem may also be our use of redis2.1.0 redis 2.4.0 No need to manually return requires a manual return of Redis, and some of our calls are not returned, causing the connection to be used for a long time, such as our own rewritten class com. Gaochao. Oa.module.sso.ticket.registry.RedisTicketRegistry.java 's gettickets Only get the resources, and there is no place to return. If this is frequently called, in a short period of time it is very likely to be in the case of the lack of resources connected to the situation. As follows:
/** * @author ** * @date 2013-7-15 afternoon 10:13:19 * @see Org.jasig.cas.ticket.registry.ticketregistry#gettickets () * @return */public collection <ticket> gettickets () {jedis jedis = null;jedis = getresource (); Map<byte[], byte[]> map = jedis.hgetall (sso_hash_id); if (CollectionUtils.isEmpty (map) ) {return new ArrayList<Ticket> ();} Map<string, ticket> result = new hashmap (Map.size ()); for (Iterator<Map.Entry <byte[], byte[]>> iterator = map.entryset (). iterator (); iterator.hasnext ();) {map.entry<byte[], byte[]> entry = iterator.next ();//Object jsonValue = redisserializer.parseobject (Entry.getvalue ()); String ticketid = new string (Entry.getkey ()); Ticket ticket = getticket (Ticketid); if (Ticket ! = null) {result.put (Ticketid, ticket);}} Return result.values ();}
For the above questions, it is recommended
1.redis for redis 2.4.0 above version;
2. For Our own classes, where redis resources must be released ( where Redis is generally used, there is a Finally , the code that must eventually be executed is responsible for returning the connection)
As follows:
finally {Ioutils.close (OIS), if (borroworoprsuccess) {//Return to resource pool Returnresource (Jedis);}}
In addition, other reasons may be network anomalies, Redis server exceptions, and so on.
Pre-section Initial solution is to restart SSO, Redis server every two days, and after the day of the code to the day, will get the resources not released after the code to repair all.
This article is from the "South Lake Miner Technology Space" blog, please be sure to keep this source http://jncumter.blog.51cto.com/812546/1615620
Redis2.1.0:could not get a resource analysis from the pool