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

createNamespace(sName) with existing name ...should throw? #92

Open
osher opened this issue Dec 12, 2016 · 0 comments
Open

createNamespace(sName) with existing name ...should throw? #92

osher opened this issue Dec 12, 2016 · 0 comments

Comments

@osher
Copy link

osher commented Dec 12, 2016

Perhaps I do not understand the full intent of the module, but here is MHO.

I observed an error prone behavior:

> cls = require('continuation-local-storage');
{ getNamespace: [Function: get], 
...
> foo = cls.createNamespace('foo');
Namespace {
...
> foo1 = cls.createNamespace('foo');
Namespace {
...
> foo1 == foo2
false

from here on, foo1 is effectively a useless reference.

implications

If by any circumstances two different "space owners" chose the same name, the first of them to create his store is prompted to lose data, and the second may find there data he does not expect.

This is a behavior that would be very taunting to detect on dev-time.

My take on this

I suspect that in order to allow this behavior be discovered in development-time - we should do one of the following:

1. Assure namespaces never collide

throw an error when trying to create a space for a name in use.
This will assure that namespaces never collide. Packages use cls.get and only the context file (the one ran with node) does cls.create.

We may consider supporting symbols as namespace identifiers. Using namespaces across packages will require them all a reference to the same symbol - however, that's something that is done deliberately and intentionally - so it's like developer taking responsibility.

2. Create rules namespaces can be shared safely

  1. createNamespace(name) and getNamespace(name) should do the same: if the space is there - it's returned, if not - it's created.

  2. namespace.set(k,v) should return a value that indicates if a value is overwritten or not.

     OR
    
  3. use namespace.const(k,v) - throws when set a second time.

  4. namespace.const(k,v,true) - the developer takes responsibility on replacing a constant)

    OR BOTH 1+2 AND 3+4

Thoughts?

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

No branches or pull requests

1 participant