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

socketTimeout trigger on empty lines #269

Closed
ronag opened this issue Jul 29, 2020 · 3 comments
Closed

socketTimeout trigger on empty lines #269

ronag opened this issue Jul 29, 2020 · 3 comments
Labels
Status: help-wanted This issue/pr is open for contributions

Comments

@ronag
Copy link
Member

ronag commented Jul 29, 2020

const { Client } = require('./')
const stream = require('stream')

// CouchDB server
const client = new Client('http://localhost:5984', {
  socketTimeout: 15e3,
  headersTimeout: 15e3
})

client.stream({
  method: 'GET',
  path: '/nxt/_changes?feed=continuous&heartbeat=5000'
}, () => new stream.Writable({
  write (chunk, encoding, callback) {
    console.error(String(chunk))
    callback()
  }
}))

let x = 0
setInterval(() => {
  console.error("# ", x++)
}, 1e3)

Also logging inside kOnBody and kOnExecute in Parser will give the following output:

kOnExecute
#  0
#  1
#  2
#  3
#  4
kOnBody


kOnExecute
#  5
#  6
#  7
#  8
#  9
kOnBody


kOnExecute
#  10
#  11
#  12
#  13
#  14
kOnBody


#  15
#  16
#  17
#  18
#  19
kOnBody


#  20
#  21
#  22
#  23
#  24
kOnBody

Notice how kOnExecute does not seem to be invoked on empty lines?

@ronag ronag added bug Something isn't working Status: help-wanted This issue/pr is open for contributions labels Jul 29, 2020
ronag added a commit that referenced this issue Jul 29, 2020
ronag added a commit that referenced this issue Jul 29, 2020
@ronag
Copy link
Member Author

ronag commented Jul 29, 2020

So the response from the server looks something like this:

HTTP/1.1 200 OK\r\n
Transfer-Encoding: chunked\r\n
Server: CouchDB/1.6.1 (Erlang OTP/17)\r\n
Date: Wed, 29 Jul 2020 10:06:14 GMT\r\n
Content-Type: text/plain; charset=utf-8\r\n
Cache-Control: must-revalidate\r\n
\r\n
1\r\n
\n\r\n
1\r\n
\n\r\n
1\r\n
\n\r\n
1\r\n
\n\r\n

Basically it's long polling chunked response which sends \n as a heartbeat. It seems to me that for some reason a line of \n in some combination doesn't invoke kOnExecute but does invoke kOnBody.

Maybe related https://github.com/nodejs/node/blob/master/src/node_http_parser.cc#L665?

Might also explain #268

@indutny @addaleax Do you have any ideas?

I don't think we currently encounter this in node core since the node http client doesn't use the consume API.

@ronag ronag removed the bug Something isn't working label Jul 29, 2020
@ronag
Copy link
Member Author

ronag commented Jul 29, 2020

Added a workaround. Would be interesting to fix "properly".

@ronag
Copy link
Member Author

ronag commented Jul 31, 2020

Node bug nodejs/node#34578

@ronag ronag closed this as completed Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: help-wanted This issue/pr is open for contributions
Projects
None yet
Development

No branches or pull requests

1 participant