Skip to content

do not attach request decorations to the prototype#3795

Closed
cjihrig wants to merge 1 commit intohapijs:masterfrom
cjihrig:3718
Closed

do not attach request decorations to the prototype#3795
cjihrig wants to merge 1 commit intohapijs:masterfrom
cjihrig:3718

Conversation

@cjihrig
Copy link
Copy Markdown
Contributor

@cjihrig cjihrig commented May 30, 2018

This commit prevents request decorations from being attached
to the Request prototype. This was leading to decorations being
leaked between servers in the same process.

Fixes: #3718

Note: I haven't benchmarked this change.

This commit prevents request decorations from being attached
to the Request prototype. This was leading to decorations being
leaked between servers in the same process.

Fixes: #3718
// Give request access to all decorations without adding them to
// the Request prototype.
Object.setPrototypeOf(request, server._core._decorations.request);
Object.setPrototypeOf(server._core._decorations.request, proto);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there upsides to this versus the approach taken with requestApply?

Copy link
Copy Markdown
Contributor Author

@cjihrig cjihrig May 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean looping over the decorations? There shouldn't be. Depending on the number of decorators, this might be faster since you're just adjusting some pointers vs. looping. I mostly went with this approach since it seemed more similar to the existing implementation (in case code was relying on decorations being on the prototype).

EDIT: After thinking about this more, I think I prefer the looping approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes a lot of sense. I'm a little concerned by the performance warning MDN gives about setPrototypeOf() (which I can't personally confirm or deny for current-day V8). But also, setting the prototype of server._core._decorations.request to the same prototype on each request seems like it may be avoidable. Here's one idea for an alternative implementation that might have less question marks re: performance. master...devinivy:3718-alternative

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that approach better. I'm going to close this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a PR taking that approach in #3796—feel free to suggest improvements. I nabbed the test you had written here—if you'd like a proper "commit" credit for that, I'm happy to take the time.

@lock
Copy link
Copy Markdown

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request decorations leak across server instances in same process

2 participants