Skip to content

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

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

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

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

rngadam opened this issue Mar 25, 2014 · 3 comments

Comments

@rngadam
Copy link

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
Copy link
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
Copy link
Author

rngadam commented Mar 25, 2014

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

rngadam pushed a commit to letsface/node-postgres that referenced this issue Apr 24, 2014
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.
brianc added a commit that referenced this issue Apr 24, 2014
@brianc
Copy link
Owner

brianc commented May 22, 2014

closed thanks to the PR! 🎉

@brianc brianc closed this as completed May 22, 2014
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