Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not explicitly set Connection-Header. #979

Merged
merged 1 commit into from
Oct 16, 2017
Merged

Conversation

Mik13
Copy link
Contributor

@Mik13 Mik13 commented Oct 6, 2017

This commit is a follow up to #974

The Connection-Header should not be explicitly set, because the core modules are handling them (see https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js, everything connected to the shouldKeepAlive field).

This might be a breaking change, because connections are keep-alive by default (see nodejs/node#10774) as long as there are running requests. The forever parameter, which sets the keep-alive flag for the agent, activates pooling (see https://github.com/nodejs/node/blob/2043944a4c62de60e7a04e8c914b565114c4b11b/lib/_http_agent.js#L78-L103), which offers a great performance gain on top.

I did not find a possibility to test this in node, because I've only got problems when connecting to SOAP-Servers written in another language, where every second request fails.

@coveralls
Copy link

coveralls commented Oct 6, 2017

Coverage Status

Coverage remained the same at 93.59% when pulling 115bf35 on TACGmbh:forever into c94cc1c on vpulim:master.

@jsdevel
Copy link
Collaborator

jsdevel commented Oct 6, 2017

This might be a breaking change, because connections are keep-alive by default

If that's the case, are sure sure we know exactly what the repercussions are? Would it be possible to have an option instead? Like connection: 'keep-alive'?

@Mik13
Copy link
Contributor Author

Mik13 commented Oct 9, 2017

This header only effects the web service and isn't directly linked to SOAP.
HTTP/1.1 servers should implement them, see https://en.wikipedia.org/wiki/HTTP_persistent_connection

Maybe it would be better to only set the header to keep-alive, if the forever option is used. In my commit I've commented that line because I've already thought that there might be concerns.
If we uncomment that line, the behaviour will be as before.

@jsdevel
Copy link
Collaborator

jsdevel commented Oct 9, 2017

what issue did this solve for you?

@Mik13
Copy link
Contributor Author

Mik13 commented Oct 10, 2017

I communicate with a Java SOAP-Service and without this change, every second request fails, because the service closed the connection, but the https module got this connection still in its pool after the first successful request (because with #974 pooling is possible, but pooling closed connections does not make any sense).

After my change, the connection will not be closed by the counterpart and our pooled connection can be reused correctly, means every request works again.

@jsdevel
Copy link
Collaborator

jsdevel commented Oct 11, 2017

I communicate with a Java SOAP-Service and without this change, every second request fails, because the service closed the connection, but the https module got this connection still in its pool after the first successful request (because with #974 pooling is possible, but pooling closed connections does not make any sense).

I see. Well, being that most connections are keep-alive anyway, I think I'm comfortable merging this knowing that it could be a breaking change. Can you document this in the README?

@Mik13
Copy link
Contributor Author

Mik13 commented Oct 11, 2017

I've added the change to the readme

lib/http.js Outdated
@@ -43,7 +43,8 @@ HttpClient.prototype.buildRequest = function(rurl, data, exheaders, exoptions) {
'Accept': 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'none',
'Accept-Charset': 'utf-8',
'Connection': 'close',
// Connection-Header is set in the http or https core module
// 'Connection': !!exoptions.forever ? 'keep-alive' : 'close',
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this meant to be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See: #979 (comment)

Should I add "next line enables keep-alive connection only for pooled connections" to clearify that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd replace both lines with 'Connection': !!exoptions.forever ? 'keep-alive' : 'close', and call it good.

lib/http.js Outdated
@@ -43,7 +43,8 @@ HttpClient.prototype.buildRequest = function(rurl, data, exheaders, exoptions) {
'Accept': 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'none',
'Accept-Charset': 'utf-8',
'Connection': 'close',
// Connection-Header is set in the http or https core module
// 'Connection': !!exoptions.forever ? 'keep-alive' : 'close',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd replace both lines with 'Connection': !!exoptions.forever ? 'keep-alive' : 'close', and call it good.

@Mik13
Copy link
Contributor Author

Mik13 commented Oct 16, 2017

Alright, I've changed that and now the old default behaviour is restored and the forever option will now pool the keep alive connections.

@jsdevel jsdevel merged commit a10386a into vpulim:master Oct 16, 2017
@jsdevel
Copy link
Collaborator

jsdevel commented Oct 16, 2017

Thanks @Mik13 !

@Mik13 Mik13 deleted the forever branch October 17, 2017 07:00
@Mik13
Copy link
Contributor Author

Mik13 commented Oct 17, 2017

Thank you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants