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

Closed
rngadam opened this Issue Mar 25, 2014 · 3 comments

Projects

None yet

2 participants

@rngadam
rngadam commented Mar 25, 2014

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
brianc commented Mar 25, 2014

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
rngadam commented Mar 25, 2014

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

@rngadam rngadam pushed a commit to letsface/node-postgres that referenced this issue Apr 18, 2014
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 pushed a commit to letsface/node-postgres that referenced this issue Apr 24, 2014
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
brianc commented May 22, 2014

closed thanks to the PR! 🎉

@brianc brianc closed this May 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment