Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent logging of RejectedExecutionException #6217

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#### Bugs
* Fix #6038: Support for Gradle configuration cache
* Fix #6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
* Fix #6215: Suppressing rejected execution exception for port forwarder

#### Improvements
* Fix #6008: removing the optional dependency on bouncy castle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;

Expand Down Expand Up @@ -75,16 +76,20 @@ public void onOpen(final WebSocket webSocket) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
logger.debug("Error while writing client data");
if (alive.get()) {
clientThrowables.add(e);
closeBothWays(webSocket, 1001, "Client error");
}
clientError(webSocket, "writing client data", e);
}
});
}
}

private void clientError(final WebSocket webSocket, String operation, Exception e) {
if (alive.get()) {
logger.debug("Error while " + operation, e);
clientThrowables.add(e);
closeBothWays(webSocket, 1001, "Client error");
}
}

@Override
public void onMessage(WebSocket webSocket, String text) {
logger.debug("{}: onMessage(String)", LOG_PREFIX);
Expand Down Expand Up @@ -125,27 +130,27 @@ public void onMessage(WebSocket webSocket, ByteBuffer buffer) {
} else {
// Data
if (out != null) {
serialExecutor.execute(() -> {
try {
while (buffer.hasRemaining()) {
int written = out.write(buffer); // channel byte already skipped
if (written == 0) {
// out is non-blocking, prevent a busy loop
Thread.sleep(50);
try {
serialExecutor.execute(() -> {
try {
while (buffer.hasRemaining()) {
int written = out.write(buffer); // channel byte already skipped
if (written == 0) {
// out is non-blocking, prevent a busy loop
Thread.sleep(50);
}
}
webSocket.request();
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
clientError(webSocket, "forwarding data to the client", e);
}
webSocket.request();
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
if (alive.get()) {
clientThrowables.add(e);
logger.debug("Error while forwarding data to the client", e);
closeBothWays(webSocket, 1002, PROTOCOL_ERROR);
}
}
});
});
} catch (RejectedExecutionException e) {
// just ignore
}
}
}
}
Expand Down
Loading