Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

TypeError: Cannot call method 'sync' of undefined #549

Closed
rngadam opened this Issue · 3 comments

2 participants

@rngadam

node-postgres 2.8.2

Exception:

/home/rngadam/letsface/src/api-ng/node_modules/pg/lib/query.js:92
    connection.sync();
               ^
TypeError: Cannot call method 'sync' of undefined
    at Query.handleError (/home/rngadam/letsface/src/api-ng/node_modules/pg/lib/query.js:92:16)
    at Client.connect (/home/rngadam/letsface/src/api-ng/node_modules/pg/lib/client.js:167:24)
    at g (events.js:192:14)
    at EventEmitter.emit (events.js:93:17)
    at Socket.<anonymous> (/home/rngadam/letsface/src/api-ng/node_modules/pg/lib/connection.js:60:10)
    at Socket.EventEmitter.emit (events.js:93:17)
    at TCP.onread (net.js:418:51)

the relevant code:

Query.prototype.handleError = function(err, connection) {
  //need to sync after error during a prepared statement
  if(this.isPreparedStatement) {
    connection.sync();
  }

and (in pg/lib/client.js)

  con.once('end', function() {
    if(self.activeQuery) {
      var disconnectError = new Error('Stream unexpectedly ended during query execution');
      self.activeQuery.handleError(disconnectError);
      self.activeQuery = null;
    }
    self.emit('end');
  });

I think this:

 self.activeQuery.handleError(disconnectError);

should be changed to this?

 self.activeQuery.handleError(disconnectError, con);
@brianc
Owner

You are totally right! So sorry about that. :( Do you have a test case to reproduce? I will add this to the library asap.

@rngadam

It's kinda meshed into our own test setup/teardown so it would be hard to extract...

@rngadam rngadam referenced this issue from a commit in letsface/node-postgres
Ricky Ng-Adam test to reproduce behavior of issue brianc/node-postgres#549
copy of query-error-handling-tests.js
a fix was provided in 5079c1e
2e3359d
@rngadam rngadam referenced this issue from a commit in letsface/node-postgres
Ricky Ng-Adam test to reproduce behavior of issue brianc/node-postgres#549
a fix was provided in 5079c1e;
test is modeled on query-error-handling-tests.js;
test both kill query and disconnection on prepared statement execution;
make connection error string message consistent between native and non-native;
disable test server-side kill for native as it hangs;
sync can cause error to be emitted so we catch that;
we also move _ending state before _send is called.
6216f60
@brianc
Owner

closed thanks to the PR! :tada:

@brianc brianc closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.