Skip to content

Commit

Permalink
Only delete cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Jul 25, 2024
1 parent 125c103 commit 8ba4439
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions library/agent/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,13 @@ export function runWithContext<T>(context: Context, fn: () => T) {
return fn();
}

// We need to create a new context without `attackDetected`, `consumedRateLimitForIP`, ...
const topLevelContext: Context = {
url: context.url,
method: context.method,
query: context.query,
headers: context.headers,
routeParams: context.routeParams,
remoteAddress: context.remoteAddress,
body: context.body,
cookies: context.cookies,
source: context.source,
route: context.route,
graphql: context.graphql,
xml: context.xml,
subdomains: context.subdomains,
};
// Cleanup lingering cache
// In tests the context is often passed by reference
// Make sure to clean up the cache before running the function
delete context.cache;

// If there's no context yet, we create a new context and run the function with it
return ContextStorage.run(topLevelContext, fn);
return ContextStorage.run(context, fn);
}

/**
Expand Down

0 comments on commit 8ba4439

Please sign in to comment.