socket.connect gives error - "TypeError: Converting circular structure to JSON" #3910

Closed
anup opened this Issue Aug 23, 2012 · 6 comments

Projects

None yet

5 participants

@anup

This happens intermittently only on version 0.8.x. Have tested it on 0.8.0, 0.8.4 an 0.8.7. Exists in all of them. Does not happen in version 0.6.x.

The following error is on version 0.8.7.

  throw new assert.AssertionError({
        ^
<error: TypeError: Converting circular structure to JSON>
    at Object.afterConnect [as oncomplete] (net.js:725:10)
@bnoordhuis
Node.js Foundation member

Does this patch fix the issue? Or at least change the error message?

diff --git a/lib/net.js b/lib/net.js
index a97da67..72eb140 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -722,7 +722,7 @@ function afterConnect(status, handle, req, readable, writable) {
     return;
   }

-  assert.equal(handle, self._handle);
+  assert(handle === self._handle, 'handle != self._handle');

   debug('afterConnect');
@bnoordhuis
Node.js Foundation member

Also, a test case would help. I see no obvious reason why that assertion should trigger.

@dhruvbird

Is the complement of === !== or is there some js magic which makes != the complement of ===?.

@anup

@bnoordhuis It does not fix. Now I get the following error when compiled your patch on v0.8.8.

  throw new assert.AssertionError({
        ^
AssertionError: handle != self._handle
    at Object.afterConnect [as oncomplete] (net.js:726:3)

I tried simulating it with running the following for 2000 sockets, but I am unable to do so.

    var socket = new net.Stream();
    socket.connect("208.68.163.218", 5222);

The original way of replicating the same is to install and run https://github.com/dhruvbird/node-xmpp-bosh with the following command from within the src folder under the project's root directory.

node run-server.js

This will start the BOSH server.

And then in another terminal window go to the 'tests' folder under the project's root directory. And run this

node stress.js --domain=jabber.org --nsess=2000

This will try and create 2000 BOSH sessions with the BOSH server, and the BOSH server in turn tries to make 2000 socket connections with jabber.org after doing an srv lookup on jabber.org.

I believe I am getting the error in the dns-srv module https://github.com/dhruvbird/dns-srv after the call to https://github.com/dhruvbird/dns-srv/blob/master/srv.js#L177.

The socket passed to this is created at here: https://github.com/dhruvbird/node-xmpp-bosh/blob/v0.6.1/src/xmpp-proxy.js#L210

I know it will take some effort for you to simulate this, but I regret that could not make it much simpler for you. It is happening quite consistently on my mac. Also happens on CentOS as I mentioned.

Let me know if you any further details?

@anup

Forgot to mention earlier, it can be simulated on the master branch.

A few other debugging steps that I did (unsuccessfully) to get a more meaningful stack trace:

  1. Tried using https://github.com/tlrobinson/long-stack-traces. Got the same error:
assert.js:102
  throw new assert.AssertionError({
        ^
<error: TypeError: Converting circular structure to JSON>
    at Object.afterConnect [as oncomplete] (net.js:725:10)
  1. Tried using https://github.com/mattinsler/longjohn. Got the following error:
assert.js:102
  throw new assert.AssertionError({
        ^
Caught error in longjohn.  Please report this to matt.insler@gmail.com.
    at Object.afterConnect [as oncomplete] (net.js:725:10)
  1. Tried using the domains module of node 0.8.x. Got the following error:
domain.js:66
    throw er;
          ^
<error: TypeError: Converting circular structure to JSON>
    at Object.afterConnect [as oncomplete] (net.js:725:10)
@mmalecki

@tjfontaine we haven't received any reports of this recently, I think it's safe to assume that this is outdated.

@indutny indutny closed this Aug 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment