Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
olavloite opened this issue May 18, 2021 · 0 comments · Fixed by #1192
Closed
Assignees
Labels
api: spanner priority: p2 type: bug

Comments

@olavloite
Copy link
Contributor

@olavloite olavloite commented May 18, 2021

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);
  }
}
@olavloite olavloite added priority: p2 type: bug labels May 18, 2021
@olavloite olavloite self-assigned this May 18, 2021
@product-auto-label product-auto-label bot added the api: spanner label May 18, 2021
olavloite added a commit that referenced this issue May 18, 2021
An AsyncResultSet that was PAUSED and then CANCELLED, would continue to invoke the
callback until the callback would call tryNext(). If the callback never called tryNext(),
the spinning would continue until the entire result set had been consumed.

Fixes #1191
olavloite added a commit that referenced this issue May 19, 2021
…1192)

An AsyncResultSet that was PAUSED and then CANCELLED, would continue to invoke the
callback until the callback would call tryNext(). If the callback never called tryNext(),
the spinning would continue until the entire result set had been consumed.

Fixes #1191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner priority: p2 type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant