bchavez / RethinkDb.Driver

:headphones: A NoSQL C#/.NET RethinkDB database driver with 100% ReQL API coverage.
http://rethinkdb.com/api/java
Other
383 stars 134 forks source link

NullReferenceException when executing a query after a failed reconnect. #128

Closed gjhommersom closed 6 years ago

gjhommersom commented 6 years ago

Steps to reproduce:

  1. Connect with RethinkDb.
  2. Stop the RethinkDb service.
  3. Execute a query.
  4. Do a reconnect.
  5. Execute a query.

Expected result: A ReqlError indication that there is no active connection.

Actual result: A NullReferenceException.

Other information: The exception occurs because the pump is not set due to reconnect failing. Checking if the connection is open would fix this problem.

Affected code:

public virtual Task<Response> SendQuery(long token, string json, bool awaitResponse, CancellationToken cancelToken)
{
    cancelToken.ThrowIfCancellationRequested();
    if( pump.IsCancellationRequested )
    {
        throw new ReqlDriverError($"Threads may not {nameof(SendQuery)} because the connection is shutting down.");
    }

    ...
}