skonves / express-http-context

Get and set request-scoped context anywhere
MIT License
299 stars 26 forks source link

how is Concurrenct requests are handled for this package, if i set request object with the same request name?? #54

Closed lioulbehailu closed 3 years ago

lioulbehailu commented 3 years ago

if i share the user permission object with the same name like so

httpContext.set('permission', permission);

and if concurrent requests reach the express server, wont't this same the permission object to the unintended user due to

  1. same permission name, or due to
  2. some blocking code holding one request and the other concurrent request changing the permission object, and by the time the first request finishes it's task it get the updated permission object, which it doesn't belong to it
cullin-lam-simplisafe commented 2 years ago

@lioulbehailu Was your guess correct? Im concerned with this too since it uses a static namespace

cullin-lam-simplisafe commented 2 years ago

I found this from cls-hooked

Values are grouped into namespaces, created with createNamespace(). Sets of function calls are grouped together by calling them within the function passed to .run() on the namespace object. Calls to .run() can be nested, and each nested context this creates has its own copy of the set of values from the parent context. When a function is making multiple asynchronous calls, this allows each child call to get, set, and pass along its own context without overwriting the parent's.

It seems like the nested context will have its own copy