Skip to content

Commit

Permalink
Fixed connection leak on halthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeleon committed Dec 8, 2016
1 parent 4b4d66f commit 1c72401
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.corbel.lib.ws.health;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;

import com.codahale.metrics.health.HealthCheck;
Expand All @@ -19,10 +20,16 @@ public AuthorizationRedisHealthCheck(RedisTemplate<String, JsonObject> redisTemp

@Override
protected Result check() throws Exception {
if (redisTemplate.getConnectionFactory().getConnection().ping().equals("PONG")
&& redisTemplate.opsForSet().members("fake").size() == 0) {
return Result.healthy();
RedisConnection redis = redisTemplate.getConnectionFactory().getConnection();
try {
if (redis.ping().equals("PONG")
&& redisTemplate.opsForSet().members("fake").size() == 0) {
return Result.healthy();
}
return Result.unhealthy("Redis is down");
}
finally {
redis.close();
}
return Result.unhealthy("Redis is down");
}
}

0 comments on commit 1c72401

Please sign in to comment.