Skip to content

Commit

Permalink
feat(stream): fail pending request if server close stream without
Browse files Browse the repository at this point in the history
exception
  • Loading branch information
mattisonchao committed Nov 15, 2024
1 parent b071de7 commit c14eabf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.streamnative.oxia.proto.ReadResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CancellationException;

import lombok.NonNull;

final class ReadBatch extends BatchBase implements Batch, StreamObserver<ReadResponse> {
Expand Down Expand Up @@ -83,6 +85,12 @@ public void onError(Throwable batchError) {

@Override
public void onCompleted() {
// complete pending request if the server close stream without any response
gets.forEach(g -> {
if (!g.callback().isDone()) {
g.fail(new CancellationException());
}
});
factory.getReadRequestLatencyHistogram().recordSuccess(System.nanoTime() - startSendTimeNanos);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.streamnative.oxia.proto.WriteResponse;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -63,7 +64,16 @@ public void onError(Throwable t) {
}

@Override
public void onCompleted() {}
public void onCompleted() {
synchronized (WriteStreamWrapper.this) {
// complete pending request if the server close stream without any response
pendingWrites.forEach(f -> {
if (!f.isDone()) {
f.completeExceptionally(new CancellationException());
}
});
}
}

public CompletableFuture<WriteResponse> send(WriteRequest request) {
synchronized (WriteStreamWrapper.this) {
Expand Down

0 comments on commit c14eabf

Please sign in to comment.