Skip to content

Commit fb126fc

Browse files
committed
Fix timeout issues
1 parent e61607f commit fb126fc

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

clickhouse-cli-client/src/main/java/com/clickhouse/client/cli/ClickHouseCommandLine.java

+20-22
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static boolean check(int timeout, String command, String... args) {
6969
}
7070
return exitValue == 0;
7171
} else {
72-
log.trace("Timed out waiting for command %s to complete", list);
72+
log.trace("Timed out after waiting %d ms for command %s to complete", timeout, list);
7373
}
7474
} catch (InterruptedException e) {
7575
Thread.currentThread().interrupt();
@@ -358,33 +358,31 @@ IOException getError() {
358358
error = "";
359359
}
360360
try {
361-
if (!process.waitFor(request.getConfig().getSocketTimeout(), TimeUnit.MILLISECONDS)) {
362-
return new IOException("Timed out waiting for command to terminate");
361+
int exitValue = process.waitFor();
362+
if (exitValue != 0) {
363+
if (error.isEmpty()) {
364+
error = ClickHouseUtils.format("Command exited with value %d", exitValue);
365+
} else {
366+
int index = error.trim().indexOf('\n');
367+
error = index > 0 ? error.substring(index + 1) : error;
368+
}
369+
} else {
370+
if (!error.isEmpty()) {
371+
// TODO update response summary
372+
log.trace(() -> {
373+
for (String line : error.split("\n")) {
374+
log.trace(line);
375+
}
376+
return "";
377+
});
378+
}
379+
error = "";
363380
}
364381
} catch (InterruptedException e) {
365382
Thread.currentThread().interrupt();
366383
process.destroyForcibly();
367384
throw new CompletionException(e);
368385
}
369-
if (process.exitValue() != 0) {
370-
if (error.isEmpty()) {
371-
error = ClickHouseUtils.format("Command exited with value %d", process.exitValue());
372-
} else {
373-
int index = error.trim().indexOf('\n');
374-
error = index > 0 ? error.substring(index + 1) : error;
375-
}
376-
} else {
377-
if (!error.isEmpty()) {
378-
// TODO update response summary
379-
log.trace(() -> {
380-
for (String line : error.split("\n")) {
381-
log.trace(line);
382-
}
383-
return "";
384-
});
385-
}
386-
error = "";
387-
}
388386
}
389387
return !ClickHouseChecker.isNullOrBlank(error) ? new IOException(error) : null;
390388
}

clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseClient.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,8 @@ static ClickHouseOutputStream getAsyncRequestOutputStream(ClickHouseConfig confi
105105
final CountDownLatch latch = new CountDownLatch(1);
106106
final ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance()
107107
.createPipedOutputStream(config, () -> {
108-
long timeout = config.getSocketTimeout();
109108
try {
110-
if (timeout > 0L) {
111-
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
112-
throw new IllegalStateException(
113-
ClickHouseUtils.format("Async write timed out after %d ms", timeout));
114-
}
115-
} else {
116-
latch.await();
117-
}
109+
latch.await();
118110

119111
if (postCloseAction != null) {
120112
postCloseAction.run();

0 commit comments

Comments
 (0)