Skip to content

Cancelling and pausing an AsyncResultSet can cause the callback to be called repeatedly #1191

@olavloite

Description

@olavloite

The following test case shows that the callback will continue to be called after the callback has returned PAUSE and the result set has been cancelled. This will only happen if the callback method does not call resultSet.tryNext().

@Test
public void testCallbackIsNotCalledWhilePausedAndCanceled() throws InterruptedException, ExecutionException {
  Executor executor = Executors.newSingleThreadExecutor();
  ResultSet delegate = mock(ResultSet.class);

  final AtomicInteger callbackCounter = new AtomicInteger();

  try (AsyncResultSetImpl rs =
      new AsyncResultSetImpl(simpleProvider, delegate, AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) {
        rs.setCallback(executor,
            resultSet -> {
              callbackCounter.getAndIncrement();
              return CallbackResponse.PAUSE;
            });

    rs.cancel();

    while (callbackCounter.get() < 100) {
      Thread.yield();
    }

   assertThat(callbackCounter.get()).isGreaterThan(99);
  }
}

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/java-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions