This repository has been archived by the owner. It is now read-only.

http: v0.10 server doesn't close connection #7011

Open
bnoordhuis opened this Issue Jan 31, 2014 · 5 comments

Comments

Projects
None yet
4 participants
Member

bnoordhuis commented Jan 31, 2014

... or master does, depending on how you look at it. Either way, the behavior between master and v0.10 is different.

var http = require('http');

http.createServer(function(req, res) {
  this.close();
  res.end();
}).listen(8000, '127.0.0.1', function() {
  http.get('http://127.0.0.1:8000/', function(res) {
    // do nothing
  });
});

With v0.10:

connect(11, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
epoll_wait(5, {{EPOLLIN, {u32=10, u64=10}}, {EPOLLOUT, {u32=11, u64=11}}}, 1024, -1) = 2
accept4(10, 0, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 12
accept4(10, 0, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
write(11, "GET / HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nConnection: keep-alive\r\n\r\n", 64) = 64
epoll_ctl(5, EPOLL_CTL_ADD, 12, {EPOLLIN, {u32=12, u64=12}}) = 0
epoll_ctl(5, EPOLL_CTL_ADD, 11, {EPOLLIN, {u32=11, u64=11}}) = -1 EEXIST (File exists)
epoll_ctl(5, EPOLL_CTL_MOD, 11, {EPOLLIN, {u32=11, u64=11}}) = 0
epoll_wait(5, {{EPOLLIN, {u32=12, u64=12}}}, 1024, 119989) = 1
read(12, "GET / HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nConnection: keep-alive\r\n\r\n", 65536) = 64
write(12, "HTTP/1.1 200 OK\r\nDate: Wed, 29 Jan 2014 08:10:52 GMT\r\nConnection: keep-alive\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n", 113) = 113
epoll_ctl(5, EPOLL_CTL_MOD, 12, {EPOLLIN, {u32=12, u64=12}}) = 0
epoll_wait(5, {{EPOLLIN, {u32=11, u64=11}}}, 1024, 727) = 1
read(11, "HTTP/1.1 200 OK\r\nDate: Wed, 29 Jan 2014 08:10:52 GMT\r\nConnection: keep-alive\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n", 65536) = 113
epoll_wait(5, {}, 1024, 719)            = 0
epoll_wait(5, ^CProcess 3754 detached

With master:

connect(11, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)
epoll_ctl(5, EPOLL_CTL_ADD, 6, {EPOLLIN, {u32=6, u64=6}}) = 0
epoll_ctl(5, EPOLL_CTL_ADD, 8, {EPOLLIN, {u32=8, u64=8}}) = 0
epoll_ctl(5, EPOLL_CTL_ADD, 10, {EPOLLIN, {u32=10, u64=10}}) = 0
epoll_ctl(5, EPOLL_CTL_ADD, 11, {EPOLLOUT, {u32=11, u64=11}}) = 0
epoll_wait(5, {{EPOLLIN, {u32=10, u64=10}}, {EPOLLOUT, {u32=11, u64=11}}}, 1024, -1) = 2
accept4(10, 0, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 12
accept4(10, 0, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
write(11, "GET / HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nConnection: close\r\n\r\n", 59) = 59
epoll_ctl(5, EPOLL_CTL_ADD, 12, {EPOLLIN, {u32=12, u64=12}}) = 0
epoll_ctl(5, EPOLL_CTL_ADD, 11, {EPOLLIN, {u32=11, u64=11}}) = -1 EEXIST (File exists)
epoll_ctl(5, EPOLL_CTL_MOD, 11, {EPOLLIN, {u32=11, u64=11}}) = 0
epoll_wait(5, {{EPOLLIN, {u32=12, u64=12}}}, 1024, 119994) = 1
read(12, "GET / HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nConnection: close\r\n\r\n", 65536) = 59
write(12, "HTTP/1.1 200 OK\r\nDate: Wed, 29 Jan 2014 08:13:50 GMT\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n", 108) = 108
close(12)                               = 0
epoll_wait(5, {{EPOLLIN, {u32=11, u64=11}}}, 1024, 942) = 1
read(11, "HTTP/1.1 200 OK\r\nDate: Wed, 29 Jan 2014 08:13:50 GMT\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n", 65536) = 108
epoll_wait(5, {{EPOLLIN, {u32=11, u64=11}}}, 1024, 940) = 1
read(11, "", 65536)                     = 0
close(11)                               = 0
+++ exited with 0 +++
Owner

indutny commented Feb 28, 2014

var http = require('http');

http.createServer(function(req, res) {
  this.close();
  res.end();
}).listen(8000, '127.0.0.1', function() {
  http.get({ port: 8000, agent: false }, function(res) {
    // do nothing
  });
});

Works fine on both master and v0.10. It seems that agent just hast a bit different behavior between them. Seems like a behavior change and not a bug.

@indutny indutny closed this Feb 28, 2014

Member

bnoordhuis commented Feb 28, 2014

It seems that agent just hast a bit different behavior between them.

Of course, but where is that change in behavior documented? The http documentation doesn't mention it.

Actually, it mentions quite the opposite: it states in a few places that the agent defaults to keep-alive while the actual behavior seems to be Connection: close unless instructed otherwise.

Owner

indutny commented Feb 28, 2014

Ok, reopening. But it will most likely not be a priority issue for me, so if you or anyone else wish - a PR, fixing the documentation would be highly welcome!

@indutny indutny reopened this Feb 28, 2014

Owner

jasnell commented May 28, 2015

@bnoordhuis ... is this still an issue for you?

Member

bnoordhuis commented May 29, 2015

No, and it never was. :-) But I believe the documentation is still wrong in a couple of places.

@jasnell jasnell added doc P-3 labels Jun 3, 2015

rjbernaldo added a commit to rjbernaldo/node-v0.x-archive that referenced this issue Jun 12, 2015

http.markdown: fixes docs to reflect change in default Agent behavior…
… between v0.10 (Connection: keepAlive) and master (Connection: close).

This commit is a fix for #7011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.