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

Cursors (or streams) produces an infinite loop #207

Closed
ProgMaq opened this issue Jan 21, 2021 · 2 comments
Closed

Cursors (or streams) produces an infinite loop #207

ProgMaq opened this issue Jan 21, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@ProgMaq
Copy link

ProgMaq commented Jan 21, 2021

Version

4.0.1-SNAPSHOT

Context

When using the cursors or stream an infinite loop is produced, stream.exceptionHandler or stream.endHandler will never be called. hasMore always indicates true.

Do you have a reproducer?

package org.example;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.jdbcclient.JDBCPool;

public class Example {

  public static void main(String[] args) {

    final Vertx vertx = Vertx.vertx();

    final JsonObject config = new JsonObject()
      .put("provider_class", "io.vertx.ext.jdbc.spi.impl.HikariCPDataSourceProvider")
      .put("jdbcUrl", "jdbc:sqlserver://****:1433;databaseName=****;")
      .put("driverClassName", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
      .put("username", "****")
      .put("password", "****")
      .put("max_pool_size", 1)
      .put("initial_pool_size", 1)
      .put("min_pool_size", 1)
      .put("max_statements", 0)
      .put("max_statements_per_connection", 0)
      .put("max_idle_time", 0);

    final JDBCPool pool = JDBCPool.pool(vertx, config);

    pool.withTransaction(tx ->
      tx.prepare("SELECT 1")
        .map(pS -> pS.createStream(200))
        .flatMap(stream -> Future
          .future(promise -> {

            stream.exceptionHandler(err -> {
              System.out.println("Error: " + err.getMessage());
              promise.fail(err);
            });

            stream.endHandler(v -> {
              System.out.println("End of stream");
              promise.complete();
            });

            stream.handler(row -> {
              System.out.println(row.toJson().encode());
            });

          })
        )
    )
        .onFailure(Throwable::printStackTrace);

  }

}

Steps to reproduce

  1. Add valid credentials
  2. Create a basic POM with mssql driver and vertx-jdbc-client dependencies
  3. Run

Extra

  • MacOS 11.1
  • AdoptOpenJDK (build 15.0.1+9)
  • I have used stable versions of the MSSQL driver, and the latest one (9.1.1.jre15-preview) with the same results.
  • I have used c3p0, Hikari and Agroal, also the same result.
  • With Vert.x 4.0.0 it returns 'The statement must be executed before any results can be obtained'.
  • I can avoid the infinite loop with one of these changes, but I understand that it could have repercussions:

ConnectionImpl.java: Line 126 -> change true to false

private <R> void handle(JDBCQueryAction<?, R> action, QueryResultHandler<R> handler, Promise<Boolean> promise) {
        Future<JDBCResponse<R>> fut = conn.schedule(action);
        fut.onComplete(ar -> {
            if (ar.succeeded()) {
                ar.result()
                  .handle(handler);

                promise.complete(false);
            } else {
                promise.fail(ar.cause());
            }
        });
    }

Or change CursorImpl.java: Line 66 -> ignore isSuspended value and always return false

    public synchronized boolean hasMore() {
        if (result == null) {
            throw new IllegalStateException("No current cursor read");
        }
        return false;
    }

jdbc

@ProgMaq ProgMaq added the bug label Jan 21, 2021
@vietj vietj added this to the 4.0.1 milestone Jan 21, 2021
@vietj vietj assigned vietj and unassigned pmlopes Feb 2, 2021
@vietj
Copy link
Contributor

vietj commented Feb 2, 2021

we will fix this issue by loading everything in memory for 4.0.1 and reimplement it properly for a later version

@vietj
Copy link
Contributor

vietj commented Feb 2, 2021

@ProgMaq we will do a quick fix for 4.0.1 based on your suggestion and after we will implement a better solution (#208)

btw cool usage of withTransaction and Future.future in the test

@vietj vietj closed this as completed in 84b1f1d Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants