brianc / node-libpq

Simple, low level native bindings to PostgreSQL's libpq from node.js
112 stars 42 forks source link

Fix #Ref() & #Unref() usage #7

Closed brianc closed 9 years ago

brianc commented 9 years ago

There were scenarios under heavy memory pressure where the connection would be garbage collected before it was finished working because the #Ref() was released after each query. This changes the behavior to hold a #Ref() to the object -- and prevent garbage collection -- for as long as there is an open connection to the backend. This prevents a bunch of weird, tricky race-conditions, cleans up the code, and brings it in-line with how other sockets behave. It properly blocks the event-loop until it's cleaned up.