Skip to content

Commit e1fc3af

Browse files
authored
Yaml tests: Add protection against infinite continuation loops (#3182)
1 parent 62c51b7 commit e1fc3af

File tree

1 file changed

+11
-2
lines changed
  • yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command

1 file changed

+11
-2
lines changed

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command/QueryExecutor.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,15 @@ public class QueryExecutor {
102102
public Continuation execute(@Nonnull RelationalConnection connection, @Nullable Continuation continuation,
103103
@Nonnull QueryConfig config, boolean checkCache, @Nullable Integer maxRows) throws RelationalException {
104104
final var currentQuery = config.decorateQuery(query);
105-
if (continuation == null || continuation.atBeginning()) {
105+
if (continuation == null) {
106+
// no continuation - start the query execution from the beginning
106107
return executeQuery(connection, config, currentQuery, checkCache, maxRows);
108+
} else if (continuation.atBeginning()) {
109+
// Continuation cannot be at beginning if it was returned from a query
110+
reportTestFailure("Received continuation shouldn't be at beginning");
111+
return null;
107112
} else {
113+
// Have a continuation - continue
108114
return executeContinuation(connection, continuation, config, maxRows);
109115
}
110116
}
@@ -238,14 +244,17 @@ private Object executeStatementWithForcedContinuations(final @Nonnull Statement
238244
// Have continuations - keep running the query
239245
Continuation continuation = resultSet.getContinuation();
240246
while (!continuation.atEnd()) {
247+
if (continuation.atBeginning()) {
248+
reportTestFailure("Received continuation shouldn't be at beginning");
249+
}
241250
try (var s2 = prepareContinuationStatement(connection, continuation, FORCED_MAX_ROWS)) {
242251
resultSet = (RelationalResultSet)executeStatement(s2, null);
243252
final boolean hasNext = resultSet.next(); // Initialize result set value retrieval. Has only one row.
244253
continuation = resultSet.getContinuation();
245254
if (!continuation.atEnd()) {
246255
results.add(resultSet);
247256
} else {
248-
// We assume that the last result is empty because of the maxWors:1
257+
// We assume that the last result is empty because of the maxRows:1
249258
Assertions.assertFalse(hasNext);
250259
}
251260
}

0 commit comments

Comments
 (0)