Skip to content

Requiring native bindings polutes 'global' #984

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

Merged
merged 4 commits into from
Apr 8, 2016
Merged

Requiring native bindings polutes 'global' #984

merged 4 commits into from
Apr 8, 2016

Conversation

brianc
Copy link
Owner

@brianc brianc commented Apr 8, 2016

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

brianc commented Apr 8, 2016

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

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

brianc commented Apr 8, 2016

fixed - pushing new patch version to npm now

@brianc brianc deleted the issues/981 branch April 8, 2016 23:46
@martinkuba
Copy link
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