Commit b1683819 authored by zeroleak's avatar zeroleak
Browse files

fix resource exhaustion too many threads #7

parent 7d4ad1b4
......@@ -127,7 +127,7 @@ public class JavaHttpClient implements IHttpClient {
return result;
}
private HttpClient getHttpClient(boolean isRegisterOutput) throws Exception {
public HttpClient getHttpClient(boolean isRegisterOutput) throws Exception {
if (!isRegisterOutput) {
if (httpClientShared == null) {
if (log.isDebugEnabled()) {
......@@ -162,7 +162,7 @@ public class JavaHttpClient implements IHttpClient {
} catch (Exception e) {
}
if (log.isDebugEnabled()) {
log.debug("clear httpClientShared");
log.debug("--httpClientShared");
}
httpClientShared = null;
}
......@@ -173,7 +173,7 @@ public class JavaHttpClient implements IHttpClient {
} catch (Exception e) {
}
if (log.isDebugEnabled()) {
log.debug("clear httpClientRegOut");
log.debug("--httpClientRegOut");
}
httpClientRegOut = null;
}
......
package com.samourai.stomp.client;
import com.samourai.http.client.JavaHttpClient;
import com.samourai.whirlpool.cli.config.CliConfig;
import com.samourai.whirlpool.cli.services.CliTorClientService;
import com.samourai.whirlpool.cli.services.JavaHttpClientService;
import com.samourai.whirlpool.cli.utils.CliUtils;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.utils.ClientUtils;
......@@ -18,6 +20,7 @@ import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaders;
import org.springframework.messaging.simp.stomp.StompSession;
import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.socket.WebSocketHttpHeaders;
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
......@@ -33,13 +36,21 @@ public class JavaStompClient implements IStompClient {
private CliTorClientService torClientService;
private CliConfig cliConfig;
private JavaHttpClient httpClientService;
private TaskScheduler taskScheduler;
private WebSocketStompClient stompClient;
private StompSession stompSession;
public JavaStompClient(CliTorClientService torClientService, CliConfig cliConfig) {
public JavaStompClient(
CliTorClientService torClientService,
CliConfig cliConfig,
JavaHttpClientService httpClientService,
ThreadPoolTaskScheduler taskScheduler) {
this.torClientService = torClientService;
this.cliConfig = cliConfig;
this.httpClientService = httpClientService;
this.taskScheduler = taskScheduler;
}
@Override
......@@ -151,16 +162,11 @@ public class JavaStompClient implements IStompClient {
}
private WebSocketStompClient computeStompClient() throws Exception {
// enable heartbeat (mandatory to detect client disconnect)
ThreadPoolTaskScheduler te = new ThreadPoolTaskScheduler();
te.setPoolSize(1);
te.setThreadNamePrefix("wss-heartbeat-thread-");
te.initialize();
SockJsClient webSocketClient = computeWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
stompClient.setTaskScheduler(te);
// enable heartbeat (mandatory to detect client disconnect)
stompClient.setTaskScheduler(taskScheduler);
stompClient.setDefaultHeartbeat(new long[] {HEARTBEAT_DELAY, HEARTBEAT_DELAY});
return stompClient;
}
......@@ -170,7 +176,7 @@ public class JavaStompClient implements IStompClient {
}
private SockJsClient computeWebSocketClient() throws Exception {
HttpClient jettyHttpClient = computeHttpClient();
HttpClient jettyHttpClient = httpClientService.getHttpClient(false);
if (log.isDebugEnabled()) {
log.debug("Using websocket transports: Websocket, XHR");
......
......@@ -65,7 +65,8 @@ public class TorOnionProxyInstance implements JavaTorConnexion {
log.error("", e);
stop();
}
});
},
"start-TorOnionProxyInstance");
startThread.start();
}
......@@ -132,7 +133,8 @@ public class TorOnionProxyInstance implements JavaTorConnexion {
new Thread(
() -> {
stop();
})
},
"stop-torOnionProxyInstance")
.start();
/*try {
onionProxyManager.killTorProcess();
......
......@@ -4,20 +4,33 @@ import com.samourai.stomp.client.IStompClient;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.stomp.client.JavaStompClient;
import com.samourai.whirlpool.cli.config.CliConfig;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Service;
@Service
public class JavaStompClientService implements IStompClientService {
private CliTorClientService torClientService;
private CliConfig cliConfig;
private JavaHttpClientService httpClientService;
public JavaStompClientService(CliTorClientService torClientService, CliConfig cliConfig) {
private ThreadPoolTaskScheduler taskScheduler;
public JavaStompClientService(
CliTorClientService torClientService,
CliConfig cliConfig,
JavaHttpClientService httpClientService) {
this.torClientService = torClientService;
this.cliConfig = cliConfig;
this.httpClientService = httpClientService;
taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(1);
taskScheduler.setThreadNamePrefix("stomp-heartbeat");
taskScheduler.initialize();
}
@Override
public IStompClient newStompClient() {
return new JavaStompClient(torClientService, cliConfig);
return new JavaStompClient(torClientService, cliConfig, httpClientService, taskScheduler);
}
}
......@@ -72,8 +72,8 @@ public class CliWallet extends WhirlpoolWallet {
}
@Override
public void onMixSuccess(MixSuccess mixSuccess, WhirlpoolUtxo whirlpoolUtxo) {
super.onMixSuccess(mixSuccess, whirlpoolUtxo);
public void onMixSuccess(WhirlpoolUtxo whirlpoolUtxo, MixSuccess mixSuccess) {
super.onMixSuccess(whirlpoolUtxo, mixSuccess);
// change Tor identity
cliTorClientService.changeIdentity();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment