spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

maximum call stack exceeded #147

Closed jonathanong closed 10 years ago

jonathanong commented 10 years ago
Jonathans-MacBook-Pro:proxy.js jong$ node --harmony-generators test/request.js 
events.js:65
EventEmitter.prototype.emit = function(type) {
                                      ^
RangeError: Maximum call stack size exceeded
    at TLSSocket.EventEmitter.emit (events.js:65:39)
    at Connection.<anonymous> (/Users/jong/Workspace/normalize/proxy.js/node_modules/spdy/lib/spdy/client.js:73:12)
    at Connection.EventEmitter.emit (events.js:104:17)
    at TLSSocket.onSocketError (/Users/jong/Workspace/normalize/proxy.js/node_modules/spdy/lib/spdy/connection.js:144:10)
    at TLSSocket.EventEmitter.emit (events.js:126:20)
    at Connection.<anonymous> (/Users/jong/Workspace/normalize/proxy.js/node_modules/spdy/lib/spdy/client.js:73:12)
    at Connection.EventEmitter.emit (events.js:104:17)
    at TLSSocket.onSocketError (/Users/jong/Workspace/normalize/proxy.js/node_modules/spdy/lib/spdy/connection.js:144:10)
    at TLSSocket.EventEmitter.emit (events.js:126:20)
    at Connection.<anonymous> (/Users/jong/Workspace/normalize/proxy.js/node_modules/spdy/lib/spdy/client.js:73:12)

my test case:


var https = require('https')
var spdy = require('spdy')

request.port = 4444

module.exports = request

function* request(path) {
  var agent = spdy.createAgent({
    // host: 'localhost',
    port: request.port,
  })

  var req = https.request({
    host: 'localhost',
    // port: request.port,
    agent: agent,
    method: 'GET',
    path: path,
    rejectUnauthorized: false,
  })

  var res = yield function (done) {
    req.once('response', function (res) {
      done(null, res)
    })
    req.once('error', function (err) {
      console.error(err.stack)
    })
    req.end()
  }

  return res
}

require('co')(function* () {
  yield* request('/remotes.json')
})()

pretty sure it's hiding an error, so i'm not exactly sure what i'm doing wrong. if you're interested in the server code: https://github.com/normalize/proxy.js/blob/master/app/server.js

indutny commented 10 years ago

Thank you!

/cc @mranney (looks like it)

indutny commented 10 years ago

@mranney: nvm, looks like a client problem.

indutny commented 10 years ago

@jonathanong will following patch fix it for you?

diff --git a/lib/spdy/client.js b/lib/spdy/client.js
index d0eb1f2..2170d9b 100644
--- a/lib/spdy/client.js
+++ b/lib/spdy/client.js
@@ -70,7 +70,7 @@ proto._init = function init() {
   state.connection = connection;

   connection.on('error', function(err) {
-    socket.emit('error', err);
+    self.emit('error', err);
   });

   // Select SPDY version
jonathanong commented 10 years ago

btw it's a self-signed certificate problem.

jonathanong commented 10 years ago

yup that patch works! i was just console.error(err.stack)ing the error there to see what was going on

indutny commented 10 years ago

Ok, I'll try writing test for it and will publish it tomorrow. If you are interesting - you could try helping me with test ;)

jonathanong commented 10 years ago

haha looking at it now. i copied your keys and stuff, but i get the self-signed certificate error, but you don't. trying to figure out why

jonathanong commented 10 years ago

oh got it

jonathanong commented 10 years ago

the error is thrown on the agent, not the request, which threw me off a little bit. patch incoming!