question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Context is preserved between two runPromise calls

See original GitHub issue

Running the command in sequence preserves the context. I would expect that each call would create a clean context, like is the case with run

Is that normal behavior?

    await namespace.runPromise(async () => {
        set("foo", "bar");
        const foo = get("foo");
        console.log("VAELU", foo);
      })
     
    await namespace.runPromise(async () => {
      const foo = get("foo");
      console.log("Value", foo); // Here is prints "bar" instead of undefined
    });

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:34

github_iconTop GitHub Comments

10reactions
samwymacommented, Jan 3, 2021

Just come across this issue, too. Changed to using runAndReturn instead, and that seems to have fixed it for me. Should just be a literal swap out since it will be returning the promise of your async methods

2reactions
yagodoreacommented, Oct 20, 2020

I’m dealing with something like this. I have a system that receives HTTP requests and also subscribes to Pubsub topics, it creates a new context for each HTTP request (with ns.run()) and every Pubsub message (with ns.runAndReturn()).

Each transaction is supposed to generate a new transactionId (UUID), unless it is sent over by headers or in the message metadata, in that case a new context is created with but with the received transactionId, so we can trace the related transactions over our microservices.

The problem is we’re seeing the same transactionId being repeated a lot across thousands of different unrelated requests, and we can only assume it’s an issue with cls-hooked (and not the uuid generation lib).

I don’t know if it’s related to this issue, because I’m not using the ns.runPromise(), but it might be… I’m not yet able to consistently reproduce it, and as soon as I can, I’ll post here or create a separate issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Context is preserved between two runPromise calls -
Running the command in sequence preserves the context. I would expect that each call would create a clean context, like is the case...
Read more >
Memory leak in cls-hooked or wrong use? - node.js
There is a function destroy(id) inside cls-hooked/context.js but that it is never called. I tried also ns.bind, ns.runPromise (which does a ns.
Read more >
cls-hooked | Yarn - Package Manager
Application-specific namespaces group values local to the set of functions whose calls originate from a callback passed to namespace.run() or namespace.bind() .
Read more >
Keeping request context over the function call stack - Medium
The SSENSE ecosystem is composed of multiple applications and services, each of ... Below is an example of a call between two services:....
Read more >
NetSuite Applications Suite - Oracle Help Center
Cloud · Cloud Applications · NetSuite. NetSuite Applications Suite. Table of Contents; Search. Contents. Expand AllCollapse All.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found