From 12cc7d53d86d8f6133e49909851abe19dc51da1f Mon Sep 17 00:00:00 2001 From: bmc Date: Sun, 30 Jun 2013 12:03:27 -0700 Subject: [PATCH 1/2] Add failing test for native quick disconnect hang --- test/integration/client/quick-disconnect-tests.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/integration/client/quick-disconnect-tests.js diff --git a/test/integration/client/quick-disconnect-tests.js b/test/integration/client/quick-disconnect-tests.js new file mode 100644 index 0000000..a1b6bab --- /dev/null +++ b/test/integration/client/quick-disconnect-tests.js @@ -0,0 +1,7 @@ +//test for issue #320 +// +var helper = require('./test-helper'); + +var client = new helper.pg.Client(helper.config); +client.connect(); +client.end(); From 75181492f2069b00df87750fab7d95e5ba6383cb Mon Sep 17 00:00:00 2001 From: bmc Date: Sun, 30 Jun 2013 12:03:58 -0700 Subject: [PATCH 2/2] Fix native quick disconnect hang Do not initialize connection if connection has been ended --- src/binding.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/binding.cc b/src/binding.cc index e0b087e..0ad0cdb 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -6,7 +6,7 @@ #include #define LOG(msg) printf("%s\n",msg); -#define TRACE(msg) //printf(%s\n, msg); +#define TRACE(msg) //printf("%s\n", msg); #define THROW(msg) return ThrowException(Exception::Error(String::New(msg))); @@ -251,6 +251,7 @@ public: bool copyInMode_; bool reading_; bool writing_; + bool ended_; Connection () : ObjectWrap () { connection_ = NULL; @@ -260,6 +261,7 @@ public: copyInMode_ = false; reading_ = false; writing_ = false; + ended_ = false; TRACE("Initializing ev watchers"); read_watcher_.data = this; write_watcher_.data = this; @@ -369,6 +371,7 @@ protected: //and hands off control to libev bool Connect(const char* conninfo) { + if(ended_) return true; connection_ = PQconnectStart(conninfo); if (!connection_) { @@ -660,6 +663,7 @@ protected: StopWrite(); DestroyConnection(); Emit("_end"); + ended_ = true; } private: