Skip to content

Commit 7518149

Browse files
committed
Fix native quick disconnect hang
Do not initialize connection if connection has been ended
1 parent 12cc7d5 commit 7518149

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/binding.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdlib.h>
77

88
#define LOG(msg) printf("%s\n",msg);
9-
#define TRACE(msg) //printf(%s\n, msg);
9+
#define TRACE(msg) //printf("%s\n", msg);
1010

1111

1212
#define THROW(msg) return ThrowException(Exception::Error(String::New(msg)));
@@ -251,6 +251,7 @@ class Connection : public ObjectWrap {
251251
bool copyInMode_;
252252
bool reading_;
253253
bool writing_;
254+
bool ended_;
254255
Connection () : ObjectWrap ()
255256
{
256257
connection_ = NULL;
@@ -260,6 +261,7 @@ class Connection : public ObjectWrap {
260261
copyInMode_ = false;
261262
reading_ = false;
262263
writing_ = false;
264+
ended_ = false;
263265
TRACE("Initializing ev watchers");
264266
read_watcher_.data = this;
265267
write_watcher_.data = this;
@@ -369,6 +371,7 @@ class Connection : public ObjectWrap {
369371
//and hands off control to libev
370372
bool Connect(const char* conninfo)
371373
{
374+
if(ended_) return true;
372375
connection_ = PQconnectStart(conninfo);
373376

374377
if (!connection_) {
@@ -660,6 +663,7 @@ class Connection : public ObjectWrap {
660663
StopWrite();
661664
DestroyConnection();
662665
Emit("_end");
666+
ended_ = true;
663667
}
664668

665669
private:

0 commit comments

Comments
 (0)