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

During forceReconnect, ensure reader/writer is stopped before continuing #1203

Merged
merged 2 commits into from
Aug 13, 2024
Merged
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
32 changes: 23 additions & 9 deletions src/main/java/io/nats/client/impl/NatsConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,16 @@ void forceReconnectImpl(ForceReconnectOptions options) throws InterruptedExcepti
}

// stop i/o
reader.stop(false);
writer.stop();
try {
this.reader.stop(false).get(10, TimeUnit.SECONDS);
} catch (Exception ex) {
processException(ex);
}
try {
this.writer.stop().get(10, TimeUnit.SECONDS);
} catch (Exception ex) {
processException(ex);
}

// new reader/writer
reader = new NatsConnectionReader(this);
Expand Down Expand Up @@ -704,13 +712,19 @@ void handleCommunicationIssue(Exception io) {
// Spawn a thread so we don't have timing issues with
// waiting on read/write threads
executor.submit(() -> {
try {
// any issue that brings us here is pretty serious
// so we are comfortable forcing the close
this.closeSocket(true, true);
} catch (InterruptedException e) {
processException(e);
Thread.currentThread().interrupt();
if (!tryingToConnect.get()) {
try {
tryingToConnect.set(true);

// any issue that brings us here is pretty serious
// so we are comfortable forcing the close
this.closeSocket(true, true);
} catch (InterruptedException e) {
processException(e);
Thread.currentThread().interrupt();
} finally {
tryingToConnect.set(false);
}
}
});
}
Expand Down
Loading