Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ public void flush() {
public boolean finishWrite(long length) {
lock.lock();
try {
if (state.getState() == State.TERMINAL_SUCCESS) {
return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The check only accounts for State.TERMINAL_SUCCESS. If the stream has reached a terminal failure state (e.g., TERMINAL_FAILURE), subsequent calls to finishWrite might still trigger an IllegalStateException when calling state.isFinalizing() or other methods that enforce state transitions. Consider checking for any terminal state to ensure the method is robust against all completed stream states.

// if we're already finalizing, ack rather than enqueueing again
if (state.isFinalizing() && state.getTotalSentBytes() == length) {
return true;
Expand Down Expand Up @@ -192,6 +195,10 @@ public boolean closeStream(long length) {
lock.lock();
try {

if (state.getState() == State.TERMINAL_SUCCESS) {
return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the change in finishWrite, this check only handles TERMINAL_SUCCESS. To prevent IllegalStateException when the stream has failed or been cancelled, it would be safer to check for any terminal state before proceeding with state.finalFlush(length).


boolean offer = state.finalFlush(length);
if (offer) {
internalSend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,11 @@ boolean isFinalizing() {
return false;
}

@Override
State getState() {
return State.RUNNING;
}

@Override
long getTotalSentBytes() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,9 @@ static class DirectWriteService extends StorageImplBase {
private static final Logger LOGGER = LoggerFactory.getLogger(DirectWriteService.class);
private final BiConsumer<StreamObserver<WriteObjectResponse>, List<WriteObjectRequest>> c;

private ImmutableList.Builder<WriteObjectRequest> requests;

DirectWriteService(
BiConsumer<StreamObserver<WriteObjectResponse>, List<WriteObjectRequest>> c) {
this.c = c;
this.requests = new ImmutableList.Builder<>();
}

DirectWriteService(ImmutableMap<List<WriteObjectRequest>, WriteObjectResponse> writes) {
Expand Down Expand Up @@ -420,6 +417,9 @@ private static void logUnexpectedRequest(
@Override
public StreamObserver<WriteObjectRequest> writeObject(StreamObserver<WriteObjectResponse> obs) {
return new Adapter() {
private final ImmutableList.Builder<WriteObjectRequest> requests =
new ImmutableList.Builder<>();

@Override
public void onNext(WriteObjectRequest value) {
requests.add(value);
Expand All @@ -432,7 +432,6 @@ public void onError(Throwable t) {}
public void onCompleted() {
ImmutableList<WriteObjectRequest> build = requests.build();
c.accept(obs, build);
requests = new ImmutableList.Builder<>();
}
};
}
Expand Down
Loading