express-http-context icon indicating copy to clipboard operation
express-http-context copied to clipboard

why not using node internal AsyncLocalStorage?

Open tofixx opened this issue 5 years ago • 2 comments

The current node lts supports using internal async_hooks which does not break in some reasons, cls-hooks fails.

The middleware could use https://nodejs.org/docs/latest-v14.x/api/async_hooks.html#async_hooks_asynclocalstorage_run_store_callback_args instead.

tofixx avatar Nov 17 '20 10:11 tofixx

@tofixx May i know how cls-hook is failing? Technically it is based on the same async-hooks (for nodejs ver 8+) and it should works (There are some small bugs in ns.runPromise and how memory usage is not optimized), although the API is not consistent with that of ALS.

I'm in favor for using ALS as it is optimized in V8 layer. Some microbenchmarking results here https://github.com/Darkripper214/ALS-CLS-Benchmark

@skonves I've came up with a consistent async-context package that supports v 8.12 onwards and will use Nodejs' AsyncLocalStorage when needed. It also supports the legacy methods that cls-hooked have as well. Are you open to migration? https://github.com/Darkripper214/ALS-Context

PhakornKiong avatar Mar 29 '21 16:03 PhakornKiong

The asynchronous-local-storage package has a very similar API to this one and uses AsyncLocalStorage if that helps.

dhalbrook avatar Jan 19 '22 18:01 dhalbrook