balderdashy / balderdashy/sails

Preserve async hook on call to helper

Open
#6,960 4 comments 1 reaction 0 assignees View on GitHub
help wanted more info please
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

So there is this thing called [async hooks](https://nodejs.org/api/async_hooks.html) in Node now that allow for stuff to be preserved like you would with thread local in other languages. A popular library that uses that is `cls-hooked`. This is very useful to put trace ID and add that trace to the logs when you want to do distributed logging (or add a user ID to have some context for your logs). However, the `machine` that powers sails messes up with this process and we lose the information when an helper is called. I am not sure what happens, but it is most likely related to how the `machine` that powers sails works (by making HTTP calls I believe for each helper). I think @mikermcneil would be the one to answer that since not a lot people seem to have touched this code except him...

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Sails machine's helper invocation path and how the async hook context is propagated or lost. Reproduce the loss of context around a helper call, then verify that the trace or user context remains available after the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.