Skip to content

Deadlock on YdbRepositoryTransaction#executeScanQuery #151

@std000

Description

@std000

The problem lies in the following code:

session.executeScanQuery(
    yql, sdkParams, settings,
    rs -> new ResultSetConverter(rs).stream(statement::readResult).forEach(spliterator::onNext)
).whenComplete(spliterator::onSupplierThreadComplete);

If the CompletableFuture<Status> completes before whenComplete(spliterator::onSupplierThreadComplete) is registered, then spliterator::onSupplierThreadComplete will be invoked on the main thread.

This method attempts to insert an element into an ArrayBlockingQueue<>(1). If the queue is not empty, it will lock itselft until the element is consumed. However, since the consumer (tryAdvance) runs on the same main thread, a deadlock occurs:

  • onSupplierThreadComplete blocks, waiting for the queue to be drained.
  • tryAdvance cannot proceed until onSupplierThreadComplete returns.

Eventually, onSupplierThreadComplete fails due to a timeout, and tryAdvance never receives the signal that data has ended — so it also fails.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions