Skip to content

Commit

Permalink
[mq] working branch - merge c59bcdb on top of master at c18559c
Browse files Browse the repository at this point in the history
{"baseBranch":"master","baseCommit":"c18559c89e24bd2e407a2c23dfd3608a831a2977","createdAt":"2024-05-21T15:11:37.780295Z","headSha":"c59bcdbd3483c8b67a524c4bb0d6df7b9e023a24","id":"247cd044-2ac2-403e-ba0b-78ed65d450eb","priority":"200","pullRequestNumber":"243","queuedAt":"2024-05-21T15:11:37.779733Z","status":"STATUS_QUEUED","triggeredBy":"corentin.chary@datadoghq.com"}
  • Loading branch information
dd-mergequeue[bot] authored May 21, 2024
2 parents 7e896e4 + c59bcdb commit a632aa8
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/main/java/com/timgroup/statsd/UnixStreamClientChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,33 @@ private void connect() throws IOException {
// We'd have better timeout support if we used Java 16's native Unix domain socket support (JEP 380)
delegate.setOption(UnixSocketOptions.SO_SNDTIMEO, connectionTimeout);
}
if (!delegate.connect(address)) {
if (connectionTimeout > 0 && System.nanoTime() > deadline) {
throw new IOException("Connection timed out");
try {
if (!delegate.connect(address)) {
if (connectionTimeout > 0 && System.nanoTime() > deadline) {
throw new IOException("Connection timed out");
}
if (!delegate.finishConnect()) {
throw new IOException("Connection failed");
}
}
if (!delegate.finishConnect()) {
throw new IOException("Connection failed");

delegate.setOption(UnixSocketOptions.SO_SNDTIMEO, Math.max(timeout, 0));
if (bufferSize > 0) {
delegate.setOption(UnixSocketOptions.SO_SNDBUF, bufferSize);
}
} catch (Exception e) {
try {
delegate.close();
} catch (IOException __) {
// ignore
}
throw e;
}

if (timeout > 0) {
delegate.setOption(UnixSocketOptions.SO_SNDTIMEO, timeout);
} else {
delegate.setOption(UnixSocketOptions.SO_SNDTIMEO, 0);
}
if (bufferSize > 0) {
delegate.setOption(UnixSocketOptions.SO_SNDBUF, bufferSize);
}

this.delegate = delegate;
}

@Override
public void close() throws IOException {
disconnect();
Expand Down

0 comments on commit a632aa8

Please sign in to comment.