Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3154341

Browse files
committed
use weakref for request callback
1 parent ddc519f commit 3154341

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

‎packages/node-core/src/integrations/http/httpServerIntegration.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ServerEmit = typeof Server.prototype.emit;
2424

2525
type StartSpanCallback = (next: () => boolean) => boolean;
2626
type RequestWithOptionalStartSpanCallback = IncomingMessage & {
27-
_startSpanCallback?: StartSpanCallback;
27+
_startSpanCallback?: WeakRef<StartSpanCallback>;
2828
};
2929

3030
const HTTP_SERVER_INSTRUMENTED_KEY = createContextKey('sentry_http_server_instrumented');
@@ -88,7 +88,7 @@ export interface HttpServerIntegrationOptions {
8888
* The callback will receive the next function to continue processing the request.
8989
*/
9090
export function addStartSpanCallback(request: RequestWithOptionalStartSpanCallback, callback: StartSpanCallback): void {
91-
addNonEnumerableProperty(request, '_startSpanCallback', callback);
91+
addNonEnumerableProperty(request, '_startSpanCallback', newWeakRef(callback));
9292
}
9393

9494
const _httpServerIntegration = ((options: HttpServerIntegrationOptions = {}) => {
@@ -222,7 +222,7 @@ function instrumentServer(
222222
// This is used (optionally) by the httpServerSpansIntegration to attach _startSpanCallback to the request object
223223
client.emit('httpServerRequest', request, response, normalizedRequest);
224224

225-
const callback = (request as RequestWithOptionalStartSpanCallback)._startSpanCallback;
225+
const callback = (request as RequestWithOptionalStartSpanCallback)._startSpanCallback?.deref();
226226
if (callback) {
227227
return callback(() => target.apply(thisArg, args));
228228
}

‎packages/node-core/tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"include": ["src/**/*"],
55

66
"compilerOptions": {
7-
"lib": ["es2018", "es2020.string"],
7+
"lib": ["ES2020", "ES2021.WeakRef"],
88
"module": "Node16"
99
}
1010
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /