Skip to content

Commit

Permalink
fix for issue networknt#715 - ensure cached consul connections are sp…
Browse files Browse the repository at this point in the history
…ecific to a thread to avoid concurrent use of the connections across threads (networknt#716)
  • Loading branch information
miklish authored and stevehu committed Jun 5, 2020
1 parent 7becaa2 commit 0e9b264
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void checkPass(String serviceId, String token) {
logger.trace("checkPass serviceId = {}", serviceId);
String path = "/v1/agent/check/pass/" + "check-" + serviceId;
try {
ConsulConnection consulConnection = getConnection(CHECK_PASS_CONNECTION_KEY);
ConsulConnection consulConnection = getConnection(CHECK_PASS_CONNECTION_KEY + Thread.currentThread().getId());
AtomicReference<ClientResponse> reference = consulConnection.send(Methods.PUT, path, token, null);
int statusCode = reference.get().getResponseCode();
if(statusCode >= UNUSUAL_STATUS_CODE){
Expand All @@ -121,7 +121,7 @@ public void checkFail(String serviceId, String token) {
logger.trace("checkFail serviceId = {}", serviceId);
String path = "/v1/agent/check/fail/" + "check-" + serviceId;
try {
ConsulConnection consulConnection = getConnection(CHECK_FAIL_CONNECTION_KEY);
ConsulConnection consulConnection = getConnection(CHECK_FAIL_CONNECTION_KEY + Thread.currentThread().getId());
AtomicReference<ClientResponse> reference = consulConnection.send(Methods.PUT, path, token, null);
int statusCode = reference.get().getResponseCode();
if(statusCode >= UNUSUAL_STATUS_CODE){
Expand All @@ -137,7 +137,7 @@ public void registerService(ConsulService service, String token) {
String json = service.toString();
String path = "/v1/agent/service/register";
try {
ConsulConnection consulConnection = getConnection(REGISTER_CONNECTION_KEY);
ConsulConnection consulConnection = getConnection(REGISTER_CONNECTION_KEY + Thread.currentThread().getId());
AtomicReference<ClientResponse> reference = consulConnection.send(Methods.PUT, path, token, json);
int statusCode = reference.get().getResponseCode();
if(statusCode >= UNUSUAL_STATUS_CODE){
Expand All @@ -153,7 +153,7 @@ public void registerService(ConsulService service, String token) {
public void unregisterService(String serviceId, String token) {
String path = "/v1/agent/service/deregister/" + serviceId;
try {
ConsulConnection connection = getConnection(UNREGISTER_CONNECTION_KEY);
ConsulConnection connection = getConnection(UNREGISTER_CONNECTION_KEY + Thread.currentThread().getId());
final AtomicReference<ClientResponse> reference = connection.send(Methods.PUT, path, token, null);
int statusCode = reference.get().getResponseCode();
if(statusCode >= UNUSUAL_STATUS_CODE){
Expand Down Expand Up @@ -183,7 +183,7 @@ public ConsulResponse<List<ConsulService>> lookupHealthService(String serviceNam
return null;
}

ConsulConnection connection = getConnection(serviceName);
ConsulConnection connection = getConnection(serviceName + Thread.currentThread().getId());

String path = "/v1/health/service/" + serviceName + "?passing&wait="+wait+"&index=" + lastConsulIndex;
if(tag != null) {
Expand Down

0 comments on commit 0e9b264

Please sign in to comment.