Commit 8ee83232 authored by Jimmy Lai's avatar Jimmy Lai

fix: capture async context snapshot inside requestStorage.run()

parent 62de9d1d
...@@ -4218,11 +4218,13 @@ ...@@ -4218,11 +4218,13 @@
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -2181,11 +2181,13 @@ function flushCompletedChunks(request) { ...@@ -2181,11 +2181,13 @@ function flushCompletedChunks(request) {
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -4172,11 +4172,13 @@ ...@@ -4172,11 +4172,13 @@
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -2129,11 +2129,13 @@ function flushCompletedChunks(request) { ...@@ -2129,11 +2129,13 @@ function flushCompletedChunks(request) {
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -4218,11 +4218,13 @@ ...@@ -4218,11 +4218,13 @@
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -2181,11 +2181,13 @@ function flushCompletedChunks(request) { ...@@ -2181,11 +2181,13 @@ function flushCompletedChunks(request) {
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -4172,11 +4172,13 @@ ...@@ -4172,11 +4172,13 @@
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
...@@ -2129,11 +2129,13 @@ function flushCompletedChunks(request) { ...@@ -2129,11 +2129,13 @@ function flushCompletedChunks(request) {
} }
function startWork(request) { function startWork(request) {
request.flushScheduled = null !== request.destination; request.flushScheduled = null !== request.destination;
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
scheduleMicrotask(function () { scheduleMicrotask(function () {
requestStorage.run(request, performWork, request); requestStorage.run(request, function() {
request.asyncContextSnapshot = typeof async_hooks.AsyncLocalStorage.snapshot === 'function'
? async_hooks.AsyncLocalStorage.snapshot()
: null;
performWork(request);
});
}); });
setImmediate(function () { setImmediate(function () {
10 === request.status && (request.status = 11); 10 === request.status && (request.status = 11);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment