Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sakthivelmanii committed Jan 6, 2025
1 parent 34b007c commit 25cfede
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.google.cloud.Tuple;
import com.google.cloud.grpc.GrpcTransportOptions;
import com.google.cloud.grpc.GrpcTransportOptions.ExecutorFactory;
import com.google.cloud.spanner.AsyncResultSet.StreamMessageListener;
import com.google.cloud.spanner.Options.QueryOption;
import com.google.cloud.spanner.Options.ReadOption;
import com.google.cloud.spanner.Options.TransactionOption;
Expand Down Expand Up @@ -266,6 +267,55 @@ private ResultSet wrap(final CachedResultSetSupplier resultSetSupplier) {
return new ForwardingResultSet(resultSetSupplier) {
private boolean beforeFirst = true;

@Override
public boolean initiateStreaming(StreamMessageListener streamMessageListener) {
while (true) {
try {
return internalInitiateStreaming(streamMessageListener);
} catch (SessionNotFoundException e) {
while (true) {
// Keep the replace-if-possible outside the try-block to let the exception bubble up
// if it's too late to replace the session.
replaceSessionIfPossible(e);
try {
replaceDelegate(resultSetSupplier.reload());
break;
} catch (SessionNotFoundException snfe) {
e = snfe;
// retry on yet another session.
}
}
}
}
}

private boolean internalInitiateStreaming(final StreamMessageListener streamMessageListener) {
try {
boolean ret = super.initiateStreaming(streamMessageListener);
if (beforeFirst) {
synchronized (lock) {
session.get().markUsed();
beforeFirst = false;
sessionUsedForQuery = true;
}
}
if (!ret && isSingleUse) {
close();
}
return ret;
} catch (SessionNotFoundException e) {
throw e;
} catch (SpannerException e) {
synchronized (lock) {
if (!closed && isSingleUse) {
session.get().setLastException(e);
AutoClosingReadContext.this.close();
}
}
throw e;
}
}

@Override
public boolean next() throws SpannerException {
while (true) {
Expand Down

0 comments on commit 25cfede

Please sign in to comment.