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

Error when rolling back transaction after performing only a SELECT query #43

Open
sanmadjack opened this issue Jul 4, 2014 · 4 comments
Assignees

Comments

@sanmadjack
Copy link

When I run this code:

Future _putMethod(RestRequest request) {
  return this._pool.startTransaction().then((mysql.Transaction tran) {
    return tran.prepare("SELECT * FROM files").then((mysql.Query query) {
      return query.execute().then((result) {
        // Do something?
      }).then((_) {
        this._log.info("Closing");
        query.close();
      });
    }).then((_) {
      this._log.info("Rolling");
      return tran.rollback().then((_) {
        this._log.info("Rolled");
      });
    });
  });
}

I get this output:

2014-07-04 14:35:46.528: INFO: (ConnectionPool) Starting transaction
2014-07-04 14:35:46.572: INFO: (FilesResource) Closing
2014-07-04 14:35:46.573: INFO: (FilesResource) Rolling
2014-07-04 14:35:46.574: SEVERE: (RestServer) MySQL Client Error: Connection #0 cannot process a request for Instance of '_QueryStreamHandler' while a request is already in progress for Instance of '_ExecuteQueryHandler'
Uncaught Error: Bad state: Future already completed
Stack Trace:
#0 _AsyncCompleter.completeError (dart:async/future_impl.dart:35)
#1 _handleData (package:sqljocky/src/connection.dart:211:31)
#2 _rootRunUnary (dart:async/zone.dart:730)
#3 _RootZone.runUnary (dart:async/zone.dart:864)
#4 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:488)
#5 _Future._propagateToListeners (dart:async/future_impl.dart:571)
#6 _Future._completeWithValue (dart:async/future_impl.dart:331)
#7 _Future._asyncComplete. (dart:async/future_impl.dart:393)
#8 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)
#9 _asyncRunCallback (dart:async/schedule_microtask.dart:32)
#10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:128)

Am I doing something wrong?

@sanmadjack
Copy link
Author

Just fyi, this is a simplified example of how to reproduce the issue. In reality my process should run update and insert statements, but I noticed this happening if an error occurs before actually writing anything.

@sanmadjack
Copy link
Author

If I remove the query execute, like below, it completes without error.

Future _putMethod(RestRequest request) {
  return this._pool.startTransaction().then((mysql.Transaction tran) {
    return tran.prepare("SELECT * FROM files").then((mysql.Query query) {
    }).then((_) {
      this._log.info("Rolling");
      return tran.rollback().then((_) {
        this._log.info("Rolled");
      });
    });
  });
}

@sanmadjack
Copy link
Author

I discovered that if I do something to complete the result object's stream, this error does not occur. for instance:

Future _putMethod(RestRequest request) {
  return this._pool.startTransaction().then((mysql.Transaction tran) {
    return tran.prepare("SELECT name FROM files").then((mysql.Query query) {
      return query.execute().then((result) {
        return result.toList();
        // Do something?
      }).then((_) {
        _log.info("Closing");
        query.close();
      });
    }).then((_) {
      _log.info("Rolling");
      return tran.rollback().then((_) {
        _log.info("Rolled");
      });
    });
  });
}

running result.toList() causes the result object to finish its stream, after which the transaction can be rolled back without issue.

@jamesots jamesots self-assigned this Jul 14, 2014
@jamesots
Copy link
Collaborator

jamesots commented Sep 2, 2015

Not fixed properly - need to do more work on this.

@jamesots jamesots reopened this Sep 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants