Skip to content

Requiring native bindings polutes 'global' - #984

Merged
brianc merged 4 commits into
masterfrom
issues/981
Apr 8, 2016
Merged

Requiring native bindings polutes 'global'#984
brianc merged 4 commits into
masterfrom
issues/981

Conversation

@brianc

@brianc brianc commented Apr 8, 2016

Copy link
Copy Markdown
Owner

There was some nasty global-ish variable reference updating happening when the native module 'initializes' after its require with require('pg').native

This fixes the issue by making sure both require('pg') and require('pg').native each initialize their own context in isolation and no weird global-ish references are used & subsequently stomped on.

There was some nasty global-ish variable reference updating happening when the native module 'initializes' after its require with `require('pg').native`

This fixes the issue by making sure both `require('pg')` and `require('pg').native` each initialize their own context in isolation and no weird global-ish references are used & subsequently stomped on.
@brianc

brianc commented Apr 8, 2016

Copy link
Copy Markdown
Owner Author

This fixes #981 - nice find by @vitaly-t! Thanks!

Comment thread lib/pool.js
//dictionary of all key:pool pairs
all: {},
//reference to the client constructor - can override in tests or for require('pg').native
Client: require('./client'),

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was 'punching over' this which is bad since this is a singleton. I made it not a singleton since there's no reason for it to be one, and I pass the proper constructor (native or JS) when its initialized.

@brianc
brianc merged commit a8bd44a into master Apr 8, 2016
@brianc

brianc commented Apr 8, 2016

Copy link
Copy Markdown
Owner Author

fixed - pushing new patch version to npm now

@brianc
brianc deleted the issues/981 branch April 8, 2016 23:46
@martinkuba

Copy link
Copy Markdown
Contributor

@brianc This change is breaking the newrelic instrumentation. We used to be able to wrap the client instance used by the pool, and now it's not accessible. Can we expose the client constructor on pools again? Or, can you please advise how to get around this?

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

Successfully merging this pull request may close these issues.

2 participants