Skip to content

src: do not reuse HTTPParser#25094

Closed
Drieger wants to merge 3 commits into
nodejs:masterfrom
Drieger:avoid_reuse_of_HTTPParser
Closed

src: do not reuse HTTPParser#25094
Drieger wants to merge 3 commits into
nodejs:masterfrom
Drieger:avoid_reuse_of_HTTPParser

Conversation

@Drieger
Copy link
Copy Markdown
Contributor

@Drieger Drieger commented Dec 17, 2018

Change resource being used, previously HTTParser was being reused. We are now using IncomingMessage and ClientRequest objects. The goal here is to make the async resource unique for each async operation

Refs: #24330
Refs: nodejs/diagnostics#248
Refs: #21313

Co-authored-by: Matheus Marchini matheus@sthima.com

I continued @mmarchini work on #24330 and finished what was missing. I also added a test based on @AndreasMadsen comment nodejs/diagnostics#248 (comment)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Dec 17, 2018
@Drieger Drieger force-pushed the avoid_reuse_of_HTTPParser branch from 368187e to 5d9eebd Compare December 17, 2018 19:13
@mmarchini
Copy link
Copy Markdown
Contributor

mmarchini commented Dec 17, 2018

@mmarchini
Copy link
Copy Markdown
Contributor

cc @nodejs/async_hooks @nodejs/diagnostics

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@Drieger
Copy link
Copy Markdown
Contributor Author

Drieger commented Dec 17, 2018

The problem with linter is that common is being imported but not used, but when I do not import common linter error is that it is mandatory. Any ideas how to solve this one?

@richardlau
Copy link
Copy Markdown
Member

richardlau commented Dec 17, 2018

The problem with linter is that common is being imported but not used, but when I do not import common linter error is that it is mandatory. Any ideas how to solve this one?

Just write:

require('../common');

or alternatively use common (e.g. common.mustCall).

@Flarna
Copy link
Copy Markdown
Member

Flarna commented Dec 17, 2018

If I understand this correct the resource type is still HTTPPARSER but depending on incoming/outgoing the resource passed in init differs. I think this is confusing.

Wouldn't it better to have two resource types instead?

@mscdex
Copy link
Copy Markdown
Contributor

mscdex commented Dec 18, 2018

Perhaps the commit message could be more clear. 'do not reuse HTTPParser' makes it sound as if parser objects are not being reused, when in fact it's the associated async resource that's no longer being reused (if I understand correctly).

Comment thread test/async-hooks/test-httparser-reuse.js Outdated
Copy link
Copy Markdown
Member

@AndreasMadsen AndreasMadsen left a comment

Choose a reason for hiding this comment

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

Thanks for spending time on this.

Comment thread src/async_wrap.cc Outdated
@Drieger
Copy link
Copy Markdown
Contributor Author

Drieger commented Dec 19, 2018

@Flarna maybe we could use IncomingMessage and ClientRequest instead? What do you think?

@Flarna
Copy link
Copy Markdown
Member

Flarna commented Dec 19, 2018

Not sure here; maybe prefix with Http as these names are quite generic in the global AsyncHooks scope.

Comment thread lib/_http_server.js Outdated
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.

Isn't this reusing the IncomingMessage constructor function instead of the concrete instance? If I understand the code correct the IncomingMessage instance is created in parserOnHeadersComplete.
If I'm correct I wonder why the dedicated test-httparser-reuse.js is not detecting 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.

@Drieger This one is still open and if I'm correct this is a no go.

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.

You are right @Flarna I'll investigate this more in depth.

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.

@Flarna kIncomingMessage is really a function as you said. I fixed the test to catch this.
I will also create a new object to be the resource for the server. Some other changes will be necessary as well. I will update the PR as soon as I this is working.