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

HTTP Parser issues with newline \n #34576

Closed
ronag opened this issue Jul 31, 2020 · 2 comments
Closed

HTTP Parser issues with newline \n #34576

ronag opened this issue Jul 31, 2020 · 2 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@ronag
Copy link
Member

ronag commented Jul 31, 2020

The following issue was found while working against a CouchDB changes stream which uses a newline \n as a form of a heartbeat on a long polling connection.

OS: MacOS, Node 14.6

Will invoke kOnTimeout after kOnHeadersComplete. Also will stop invoking kOnExecute but will keep invoking kOnBody.

Refs: nodejs/undici#268
Refs: nodejs/undici#269

const net = require('net')
const { HTTPParser } = process.binding('http_parser') // eslint-disable-line

net.createServer(socket => {
  socket.write('HTTP/1.1 200 OK\r\n')
  socket.write('Transfer-Encoding: chunked\r\n\r\n')
  setInterval(() => {
    socket.write('1\r\n')
    socket.write('\n\r\n')
  }, 500)
}).listen(3111)

const socket = net.connect(3111, '127.0.0.1')
const parser = new HTTPParser(HTTPParser.RESPONSE, false)
parser.initialize(
  HTTPParser.RESPONSE,
  {},
  0,
  false,
  1e3
)

parser[HTTPParser.kOnTimeout] = () => {
  console.log('kOnTimeout')
}

parser[HTTPParser.kOnHeaders] = (rawHeaders) => {
  console.log('kOnHeaders')
}

parser[HTTPParser.kOnExecute] = (ret) => {
  console.log('kOnExecute')
}

parser[HTTPParser.kOnHeadersComplete] = (versionMajor, versionMinor, rawHeaders, method,
  url, statusCode, statusMessage, upgrade, shouldKeepAlive) => {
  console.log('kOnHeadersComplete')
}

parser[HTTPParser.kOnBody] = (chunk, offset, length) => {
  console.log('kOnBody')
}

parser[HTTPParser.kOnMessageComplete] = () => {
  console.log('kOnMessageComplete')
}

parser.consume(socket._handle)
@ronag ronag added the http Issues or PRs related to the http subsystem. label Jul 31, 2020
@ronag
Copy link
Member Author

ronag commented Jul 31, 2020

@nodejs/http @addaleax @indutny

@ronag ronag changed the title HTTP Parser Issues HTTP Parser Issues with newline \n Jul 31, 2020
@ronag ronag changed the title HTTP Parser Issues with newline \n HTTP Parser issues with newline \n Jul 31, 2020
@ronag
Copy link
Member Author

ronag commented Jul 31, 2020

I think kOnExecute doesn't get executed because it keeps thinking that there is a headers timeout.

ronag added a commit to nxtedition/node that referenced this issue Jul 31, 2020
headers timeout should not occur *after* headers have been
received.

Fixes: nodejs#34576
@ronag ronag closed this as completed in da4d8de Aug 2, 2020
codebytere pushed a commit that referenced this issue Aug 5, 2020
headers timeout should not occur *after* headers have been
received.

Fixes: #34576

PR-URL: #34578
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant