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

Causes uncaught TypeError: object is not a function #42

Open
cdhowie opened this issue Sep 14, 2016 · 11 comments
Open

Causes uncaught TypeError: object is not a function #42

cdhowie opened this issue Sep 14, 2016 · 11 comments

Comments

@cdhowie
Copy link

cdhowie commented Sep 14, 2016

I'm trying to use this in combination with the AWS SDK. After some number of requests, this uncaught error is thrown:

     Uncaught TypeError: object is not a function
      at afterWrite (_stream_writable.js:354:3)
      at onwrite (_stream_writable.js:345:7)
      at WritableState.onwrite (_stream_writable.js:89:5)
      at Socket._writeGeneric (net.js:706:5)
      at Socket._writev (net.js:711:8)
      at doWrite (_stream_writable.js:298:12)
      at clearBuffer (_stream_writable.js:387:5)
      at Socket.Writable.uncork (_stream_writable.js:237:7)
      at ClientRequest._flushOutput (_http_outgoing.js:673:10)
      at ClientRequest.OutgoingMessage._flush (_http_outgoing.js:647:16)
      at _http_client.js:156:10
      at callSocketMethod (_http_client.js:552:7)
      at ClientRequest.onSocket (_http_client.js:557:7)
      at tickOnSocket (_http_client.js:523:7)
      at onSocketNT (_http_client.js:535:5)

Using the default Node agent does not cause this behavior. This is on Node 4.5.0.

@cdhowie
Copy link
Author

cdhowie commented Sep 15, 2016

I should note that I run into this behavior when using new http.Agent({ keepAlive: true }) as well, but not when using new http.Agent(). So perhaps this is an issue internal to Node itself. :(

@fengmk2
Copy link
Member

fengmk2 commented Dec 17, 2016

Can you show me a demo to reappear this problem?

@cdhowie
Copy link
Author

cdhowie commented Dec 21, 2016

I will try to produce a self-contained repro.

@ngbrown
Copy link

ngbrown commented Feb 20, 2017

I'm getting a similar error, both version 2.2.0 and 3.1.1 when trying to use it with webpack-dev-server.

_stream_writable.js:388
  cb();
  ^

TypeError: object is not a function
    at afterWrite (_stream_writable.js:388:3)
    at onwrite (_stream_writable.js:379:7)
    at WritableState.onwrite (_stream_writable.js:90:5)
    at Socket._writeGeneric (net.js:721:5)
    at Socket._write (net.js:731:8)
    at doWrite (_stream_writable.js:334:12)
    at writeOrBuffer (_stream_writable.js:320:5)
    at Socket.Writable.write (_stream_writable.js:247:11)
    at Socket.write (net.js:658:40)
    at ClientRequest.OutgoingMessage._writeRaw (_http_outgoing.js:170:23)

The error doesn't occur when not using agentkeepalive, but obviously, the connections aren't kept alive, so my Windows Authentication won't work.

@ngbrown
Copy link

ngbrown commented Feb 20, 2017

This may actually be a Node.js issue, as the default http.Agent also fails when keepAive is true.

nodejs/node#8650

@chimurai
Copy link

chimurai commented Mar 1, 2017

Same issue in this thread: chimurai/http-proxy-middleware#39 (comment)

Hopefully you guys can help to solve it.

Reproducible with a tiny example (created by @EladBezalel)
c3215-untitled.gz - source: chimurai/http-proxy-middleware#39 (comment)

https://localhost:12345/api/123 - works: browser -> server
https://localhost:3000/api/123 - fails: browser -> proxy + keepalive -> server

Here is some debug logging from the example:

$ NODE_DEBUG=http,net node index.js

[HPM] Proxy created: /  ->  http://localhost:12345/
[HPM] Subscribed to http-proxy events:  [ 'proxyReq', 'proxyRes', 'error', 'close' ]
NET 6552: listen2 null 3000 4 false undefined
NET 6552: _listen2: create a handle
NET 6552: bind to ::
NET 6552: onconnection
NET 6552: _read
NET 6552: Socket._read readStart
HTTP 6552: SERVER new http connection
[HPM] GET /api/123 -> http://localhost:12345/
NET 6552: createConnection [ { keepAliveTimeout: 30000,
    timeout: 60000,
    keepAliveMsecs: 1000,
    maxFreeSockets: 10,
    keepAlive: true,
    maxSockets: 100,
    path: null,
    localAddress: undefined,
    agent:
     Agent {
       domain: null,
       _events: [Object],
       _eventsCount: 4,
       _maxListeners: undefined,
       defaultPort: 80,
       protocol: 'http:',
       options: [Object],
       requests: {},
       sockets: [Object],
       freeSockets: {},
       keepAliveMsecs: 1000,
       keepAlive: true,
       keepAliveTimeout: 30000,
       timeout: 60000,
       maxSockets: 100,
       maxFreeSockets: 10,
       createSocketCount: 0,
       closeSocketCount: 0,
       errorSocketCount: 0,
       requestCount: 0,
       timeoutSocketCount: 0 },
    headers:
     { 'accept-language': 'en-US,en;q=0.8,nl;q=0.6',
       'accept-encoding': 'gzip, deflate, sdch, br',
       dnt: '1',
       accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
       'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
       'upgrade-insecure-requests': '1',
       'cache-control': 'no-cache',
       pragma: 'no-cache',
       connection: 'keep-alive',
       host: 'localhost:3000' },
    method: 'GET',
    secureProtocol: undefined,
    ciphers: undefined,
    ca: undefined,
    cert: undefined,
    passphrase: undefined,
    key: undefined,
    pfx: undefined,
    socketPath: undefined,
    hostname: 'localhost',
    host: 'localhost',
    port: '12345',
    servername: 'localhost',
    encoding: null } ]
NET 6552: pipe false null
NET 6552: connect: find host localhost
NET 6552: connect: dns options { family: undefined, hints: 1024 }
HTTP 6552: SERVER socketOnParserExecute 442
NET 6552: _read
NET 6552: _read wait for connection
HTTP 6552: outgoing message end.
NET 6552: afterConnect
NET 6552: _read
NET 6552: Socket._read readStart
NET 6552: onread 140
NET 6552: got data
HTTP 6552: AGENT incoming response!
HTTP 6552: AGENT isHeadResponse false
NET 6552: _read
HTTP 6552: AGENT socket keep-alive
HTTP 6552: outgoing message end.
[HPM] GET /api/123 -> http://localhost:12345/
HTTP 6552: SERVER socketOnParserExecute 540
_stream_writable.js:361
  cb();
  ^

TypeError: cb is not a function
    at afterWrite (_stream_writable.js:361:3)
    at onwrite (_stream_writable.js:352:7)
    at WritableState.onwrite (_stream_writable.js:89:5)
    at Socket._writeGeneric (net.js:714:5)
    at Socket._write (net.js:724:8)
    at doWrite (_stream_writable.js:307:12)
    at writeOrBuffer (_stream_writable.js:293:5)
    at Socket.Writable.write (_stream_writable.js:220:11)
    at Socket.write (net.js:650:40)
    at ClientRequest.OutgoingMessage._writeRaw (_http_outgoing.js:167:23)

@chimurai
Copy link

chimurai commented Mar 1, 2017

https://blogs.msdn.microsoft.com/chiranth/2013/09/20/ntlm-want-to-know-how-it-works/

Looks like it fails somewhere between 2nd request and 2nd response.

request headers [1]

{ host: 'localhost:3000',
  connection: 'keep-alive',
  pragma: 'no-cache',
  'cache-control': 'no-cache',
  'upgrade-insecure-requests': '1',
  'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
  accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  dnt: '1',
  'accept-encoding': 'gzip, deflate, sdch, br',
  'accept-language': 'en-US,en;q=0.8,nl;q=0.6' }

response headers [1]

{ 'content-length': '0',
  server: 'Microsoft-HTTPAPI/2.0',
  'www-authenticate': [ 'NTLM' ],
  date: 'Wed, 01 Mar 2017 21:16:03 GMT' }

request headers [2]

{ host: 'localhost:3000',
  connection: 'keep-alive',
  pragma: 'no-cache',
  'cache-control': 'no-cache',
  authorization: 'NTLM TlRMTVNTUAABAAAAB7IIogkACQAvAAAABwAHACgAAAAGAbEdAAAAD0NPUkUtSTdXT1JLR1JPVVA=',
  'upgrade-insecure-requests': '1',
  'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
  accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  dnt: '1',
  'accept-encoding': 'gzip, deflate, sdch, br',
  'accept-language': 'en-US,en;q=0.8,nl;q=0.6' }

response headers [2]
expecting the last response, but instead it fails.

_stream_writable.js:361
  cb();
  ^

TypeError: cb is not a function
    at afterWrite (_stream_writable.js:361:3)
    at onwrite (_stream_writable.js:352:7)
    at WritableState.onwrite (_stream_writable.js:89:5)
    at Socket._writeGeneric (net.js:714:5)
    at Socket._write (net.js:724:8)
    at doWrite (_stream_writable.js:307:12)
    at writeOrBuffer (_stream_writable.js:293:5)
    at Socket.Writable.write (_stream_writable.js:220:11)
    at Socket.write (net.js:650:40)
    at ClientRequest.OutgoingMessage._writeRaw (_http_outgoing.js:167:23)

@fengmk2
Copy link
Member

fengmk2 commented Mar 2, 2017

@chimurai Which node version?

@chimurai
Copy link

chimurai commented Mar 2, 2017

tested with v6.2.1 and v7.71

@chimurai
Copy link

chimurai commented Mar 3, 2017

Found the issue in http-proxy-middleware. (chimurai/http-proxy-middleware#149)

@ngbrown This might fix the issue you're having, since webpack-dev-server is using http-proxy-middleware to do the proxying.

@cdhowie
Copy link
Author

cdhowie commented Mar 3, 2017

There is still an issue in Node proper, however, as I encounter this error using Node's own http.Agent in keepalive mode.

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

No branches or pull requests

4 participants