Skip to content
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

process: make process.config read-only #6123

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Apr 8, 2016

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

process

Description of change

Makes process.config read-only using a getter/setter and freezing the objects on JSON.parse. Does result in a perf hit but process.config is not used in any critical paths (or any path in core) for that matter. There are apparently some places in user land where this is being extended and it causes problems when we want to add new configuration options (see #6115 for an example).

Refs: #6115

/cc @Fishrock123

@jasnell jasnell added semver-major PRs that contain breaking changes and should be released in the next major version. process Issues and PRs related to the process subsystem. labels Apr 8, 2016
@claudiorodriguez
Copy link
Contributor

CI: https://ci.nodejs.org/job/node-test-pull-request/2226/
LGTM if CI is happy
Do we have some knowledge of which userland modules extend it currently?

@Fishrock123
Copy link
Contributor

we probably need to do a bit of extended research on this one

@jasnell
Copy link
Member Author

jasnell commented Apr 8, 2016

Yep, this one is going to be just a bit problematic. There are a handful of modules that mutate process.config... for instance: https://github.com/falsecz/cson-config/blob/master/index.coffee

Salem (https://www.npmjs.com/package/salem) is a good example. Take a look at the example given:

var salem = require('salem');
var configClient = salem.createClient({
  url: 'http://localhost:8080',
  env: process.env.NODE_ENV || 'development'
});

// 
// Load the configuration for use within the application. 
// 
configClient.loadConfig(function (err, config) {
  if (err) throw err;
  process.config = config;
});

Some of these add keys to the process.config, others replace it outright... which is obviously problematic if we're going to be depending on it in any way.

Digging in further... It also looks like this could break node-gyp which does some stuff with process.config internally.

@Fishrock123
Copy link
Contributor

@jasnell what if we just keep our own internal copy?

@jasnell
Copy link
Member Author

jasnell commented Apr 9, 2016

Yep, that would work.

@jasnell
Copy link
Member Author

jasnell commented Apr 9, 2016

Essentially, we'd be conceding the process.config to userland which we would need to document. Given the way userland modules override it, users may not be able to depend on it's original purpose.

@claudiorodriguez
Copy link
Contributor

Yep, CI broken all over

gyp: Undefined variable standalone_static_library in binding.gyp while trying to load binding.gyp

@jasnell
Copy link
Member Author

jasnell commented Apr 9, 2016

Given the results I'm going to close this and look at tackling the problem a different way.

@jasnell jasnell closed this Apr 9, 2016
@ChALkeR ChALkeR mentioned this pull request Aug 3, 2016
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants