Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit ac673fe

Browse files
committed
Fixed an issue where socket read could be stuck indefinitely if there was a network adapter issue on host machine that is being read from. Instead now set the socket timeout to 10 seconds.
1 parent 892be01 commit ac673fe

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/com/zabbix/gateway/JolokiaChecker.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,22 @@
5757
public class JolokiaChecker extends ItemChecker {
5858

5959
private static final String JMX_OPERATION = "jmx.operation";
60-
6160
private static final String JMX_READ = "jmx";
61+
private static final int SOCKET_TIMEOUT = 10 * 1000; // wait for at most 10 seconds for a response
62+
private static final int CONNECTION_TIMEOUT = 5 * 1000; // wait for at most 5 seconds for
63+
// the connection to be established
6264

6365
private static final Logger logger = LoggerFactory
6466
.getLogger(JolokiaChecker.class);
67+
68+
// Performance Metrics
69+
private static final Histogram _requestSizes = Metrics.newHistogram(JolokiaChecker.class, "request-sizes");
70+
private static final Timer _requestTime = Metrics.newTimer(JolokiaChecker.class, "request-time", TimeUnit.MILLISECONDS, TimeUnit.MINUTES);
6571

6672
private J4pClient _j4pClient;
6773

6874
private Map<String, String> _foundKeys = new HashMap<String, String>();
6975
private Map<String, String> _errorKeys = new HashMap<String, String>();
70-
71-
// Performance Metrics
72-
private static final Histogram _requestSizes = Metrics.newHistogram(JolokiaChecker.class, "request-sizes");
73-
private static final Timer _requestTime = Metrics.newTimer(JolokiaChecker.class, "request-time", TimeUnit.MILLISECONDS, TimeUnit.MINUTES);
7476

7577
protected JolokiaChecker(JSONObject request) throws ZabbixException {
7678
this(request, null);
@@ -101,7 +103,8 @@ protected JolokiaChecker(JSONObject request, JmxConfiguration config) throws Zab
101103

102104
logger.debug("Jolokia URL is: " + jolokiaUrl);
103105
J4pClientBuilder builder = J4pClient.url(jolokiaUrl)
104-
.connectionTimeout(5000);
106+
.socketTimeout(SOCKET_TIMEOUT)
107+
.connectionTimeout(CONNECTION_TIMEOUT);
105108

106109
if (null != username) {
107110
builder.user(username).password(password);

0 commit comments

Comments
 (0)