Skip to content

"TypeError: Converting circular structure to JSON" when calling client.openSession() #85

Closed

Description

@walkermalling

package version 1.0.0
nodejs 16.8
os linux

Hi folks, I'm having trouble opening a session.

I'm essentially using the example code in your readme:

let statement = `...`;
const client = new DBSQLClient();
client
  .connect(connOptions)
  .then(async (client) => {
    const session = await client.openSession();
    const queryOperation = await session.executeStatement(statement, { runAsync: true });
    const result = await queryOperation.fetchAll();
    await queryOperation.close();
    console.table(result);
    await session.close();
    await client.close();
  })
  .catch((error) => {
    console.log(error);
  });

The client is successfully created, but I get the following error:

{
  "date": "Tue Nov 01 2022 11:28:52 GMT-0700 (Pacific Daylight Time)",
  "error": {},
  "exception": true,
  "level": "error",
  "message": "uncaughtException: Converting circular structure to JSON\n    --> starting at object with constructor 'TLSSocket'\n    |     property 'parser' -> object with constructor 'HTTPParser'\n    --- property 'socket' closes the circle\nTypeError: Converting circular structure to JSON\n    --> starting at object with constructor 'TLSSocket'\n    |     property 'parser' -> object with constructor 'HTTPParser'\n    --- property 'socket' closes the circle\n    at JSON.stringify (<anonymous>)\n    at exports.HttpConnection.<anonymous> (/***/node_modules/@databricks/sql/dist/DBSQLClient.js:92:69)\n    at exports.HttpConnection.emit (node:events:394:28)\n    at exports.HttpConnection.responseCallback (/***/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:12)\n    at ClientRequest.connection.responseCallback (/***/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js:67:30)\n    at Object.onceWrapper (node:events:514:26)\n    at ClientRequest.emit (node:events:394:28)\n    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:621:27)\n    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)\n    at TLSSocket.socketOnData (node:_http_client:487:22)",
  "os": { "loadavg": [0.24, 0.32, 0.35], "uptime": 519547.65 },
  "process": {
    "argv": [
      "/nix/store/p6h1iz5lcvfz1hg1z497ypa22rv52xxx-nodejs-16.8.0/bin/node",
      "/***/dbHandlers/test2.js"
    ],
    "cwd": "/***",
    "execPath": "/nix/store/p6h1iz5lcvfz1hg1z497ypa22rv52xxx-nodejs-16.8.0/bin/node",
    "gid": 100,
    "memoryUsage": {
      "arrayBuffers": 206093,
      "external": 2085823,
      "heapTotal": 17436672,
      "heapUsed": 10880032,
      "rss": 55578624
    },
    "pid": 355355,
    "uid": 1000,
    "version": "v16.8.0"
  },
  "stack": "TypeError: Converting circular structure to JSON\n    --> starting at object with constructor 'TLSSocket'\n    |     property 'parser' -> object with constructor 'HTTPParser'\n    --- property 'socket' closes the circle\n    at JSON.stringify (<anonymous>)\n    at exports.HttpConnection.<anonymous> (/***/node_modules/@databricks/sql/dist/DBSQLClient.js:92:69)\n    at exports.HttpConnection.emit (node:events:394:28)\n    at exports.HttpConnection.responseCallback (/***/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:12)\n    at ClientRequest.connection.responseCallback (/***/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js:67:30)\n    at Object.onceWrapper (node:events:514:26)\n    at ClientRequest.emit (node:events:394:28)\n    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:621:27)\n    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)\n    at TLSSocket.socketOnData (node:_http_client:487:22)",
  "trace": [
    {
      "column": null,
      "file": null,
      "function": null,
      "line": null,
      "method": null,
      "native": false
    },
    {
      "column": null,
      "file": null,
      "function": "JSON.stringify",
      "line": null,
      "method": "stringify",
      "native": false
    },
    {
      "column": 69,
      "file": "/***/node_modules/@databricks/sql/dist/DBSQLClient.js",
      "function": null,
      "line": 92,
      "method": null,
      "native": false
    },
    {
      "column": 28,
      "file": "node:events",
      "function": "exports.HttpConnection.emit",
      "line": 394,
      "method": "emit",
      "native": false
    },
    {
      "column": 12,
      "file": "/***/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js",
      "function": "exports.HttpConnection.responseCallback",
      "line": 173,
      "method": "responseCallback",
      "native": false
    },
    {
      "column": 30,
      "file": "/***/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js",
      "function": "ClientRequest.connection.responseCallback",
      "line": 67,
      "method": "responseCallback",
      "native": false
    },
    {
      "column": 26,
      "file": "node:events",
      "function": "Object.onceWrapper",
      "line": 514,
      "method": "onceWrapper",
      "native": false
    },
    {
      "column": 28,
      "file": "node:events",
      "function": "ClientRequest.emit",
      "line": 394,
      "method": "emit",
      "native": false
    },
    {
      "column": 27,
      "file": "node:_http_client",
      "function": "HTTPParser.parserOnIncomingClient [as onIncoming]",
      "line": 621,
      "method": "parserOnIncomingClient [as onIncoming]",
      "native": false
    },
    {
      "column": 17,
      "file": "node:_http_common",
      "function": "HTTPParser.parserOnHeadersComplete",
      "line": 128,
      "method": "parserOnHeadersComplete",
      "native": false
    },
    {
      "column": 22,
      "file": "node:_http_client",
      "function": "TLSSocket.socketOnData",
      "line": 487,
      "method": "socketOnData",
      "native": false
    }
  ]
}

I get this error whether the cluster is running or not.

I tried reverting back to 0.1.8-beta.2 but I get a different failure at the same step (it logs the whole request object and overflows my terminal, and terminates without throwing an error).

I've also tried various other node versions.

Activity

  1. walkermalling commented on Nov 1, 2022

    @walkermalling
    Author

    It turns out this is what happens if the token value is incorrect.

  2. kravets-levko commented on Nov 1, 2022

    @kravets-levko
  3. kravets-levko commented on Nov 4, 2022

    @kravets-levko
    Contributor

    Hi @walkermalling ! It turns out that you see an error that happened in logger while trying to log the original connection error. If possible, could you apply changes from #89 and share the actual error here? Thank you, and sorry for inconvenience

  4. Sheing commented on Dec 3, 2022

    @Sheing

    I am having the same exact issue as well.
    {"date":"Sat Dec 03 2022 22:58:47 GMT+0000 (Coordinated Universal Time)","error":{},"exception":true,"level":"error","message":"uncaughtException: Converting circular structure to JSON\n --> starting at object with constructor 'TLSSocket'\n | property 'parser' -> object with constructor 'HTTPParser'\n --- property 'socket' closes the circle\nTypeError: Converting circular structure to JSON\n --> starting at object with constructor 'TLSSocket'\n | property 'parser' -> object with constructor 'HTTPParser'\n --- property 'socket' closes the circle\n at JSON.stringify (<anonymous>)\n at exports.HttpConnection.<anonymous> (/src/app/node_modules/@databricks/sql/dist/DBSQLClient.js:92:69)\n at exports.HttpConnection.emit (node:events:513:28)\n at exports.HttpConnection.emit (node:domain:489:12)\n at exports.HttpConnection.responseCallback (/src/app/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:12)\n at ClientRequest.connection.responseCallback (/src/app/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js:67:30)\n at Object.onceWrapper (node:events:628:26)\n at ClientRequest.emit (node:events:513:28)\n at ClientRequest.emit (node:domain:489:12)\n at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:693:27)","os":{"loadavg":[0.01,0.01,0],"uptime":8002.44},"process":{"argv":["/usr/local/bin/node","/src/app/dist/index"],"cwd":"/src/app","execPath":"/usr/local/bin/node","gid":0,"memoryUsage":{"arrayBuffers":18685018,"external":20692944,"heapTotal":65355776,"heapUsed":52376888,"rss":137351168},"pid":7,"uid":0,"version":"v16.18.0"},"stack":"TypeError: Converting circular structure to JSON\n --> starting at object with constructor 'TLSSocket'\n | property 'parser' -> object with constructor 'HTTPParser'\n --- property 'socket' closes the circle\n at JSON.stringify (<anonymous>)\n at exports.HttpConnection.<anonymous> (/src/app/node_modules/@databricks/sql/dist/DBSQLClient.js:92:69)\n at exports.HttpConnection.emit (node:events:513:28)\n at exports.HttpConnection.emit (node:domain:489:12)\n at exports.HttpConnection.responseCallback (/src/app/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:12)\n at ClientRequest.connection.responseCallback (/src/app/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js:67:30)\n at Object.onceWrapper (node:events:628:26)\n at ClientRequest.emit (node:events:513:28)\n at ClientRequest.emit (node:domain:489:12)\n at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:693:27)","trace":[{"column":null,"file":null,"function":null,"line":null,"method":null,"native":false},{"column":null,"file":null,"function":"JSON.stringify","line":null,"method":"stringify","native":false},{"column":69,"file":"/src/app/node_modules/@databricks/sql/dist/DBSQLClient.js","function":null,"line":92,"method":null,"native":false},{"column":28,"file":"node:events","function":"exports.HttpConnection.emit","line":513,"method":"emit","native":false},{"column":12,"file":"node:domain","function":"exports.HttpConnection.emit","line":489,"method":"emit","native":false},{"column":12,"file":"/src/app/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js","function":"exports.HttpConnection.responseCallback","line":173,"method":"responseCallback","native":false},{"column":30,"file":"/src/app/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js","function":"ClientRequest.connection.responseCallback","line":67,"method":"responseCallback","native":false},{"column":26,"file":"node:events","function":"Object.onceWrapper","line":628,"method":"onceWrapper","native":false},{"column":28,"file":"node:events","function":"ClientRequest.emit","line":513,"method":"emit","native":false},{"column":12,"file":"node:domain","function":"ClientRequest.emit","line":489,"method":"emit","native":false},{"column":27,"file":"node:_http_client","function":"HTTPParser.parserOnIncomingClient [as onIncoming]","line":693,"method":"parserOnIncomingClient [as onIncoming]","native":false}]}

    Is this fixed in newer version?

  5. Sheing commented on Dec 4, 2022

    @Sheing

    @kravets-levko I replaced with the logger fix, and now getting 2 new diff types of error:

    THTTPException: Received a response with a bad HTTP status code: 503 {"service":"user-service"}
    {"level":"error","message":"THTTPException: Received a response with a bad HTTP status code: 503\n    at exports.HttpConnection.responseCallback (/src/app/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:26)\n    at ClientRequest.connection.responseCallback (/src/app/node_modules/@sheing/databricks-sql/dist/connection/connections/HttpConnection.js:67:30)\n    at Object.onceWrapper (node:events:628:26)\n    at ClientRequest.emit (node:events:513:28)\n    at ClientRequest.emit (node:domain:489:12)\n    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:693:27)\n    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)\n    at HTTPParser.execute (<anonymous>)\n    at TLSSocket.socketOnData (node:_http_client:534:22)\n    at TLSSocket.emit (node:events:513:28)"}
    

    and

    TApplicationException: Received a response to an unknown RPC function {"service":"user-service"}
    {"level":"error","message":"TApplicationException: Received a response to an unknown RPC function\n    at decodeCallback (/src/app/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:150:21)\n    at /src/app/node_modules/thrift/lib/nodejs/lib/thrift/buffered_transport.js:59:5\n    at IncomingMessage.<anonymous> (/src/app/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:202:46)\n    at IncomingMessage.emit (node:events:525:35)\n    at IncomingMessage.emit (node:domain:489:12)\n    at endReadableNT (node:internal/streams/readable:1358:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)"}
    
  6. fjakobs commented on Dec 8, 2022

    @fjakobs
    Contributor

    The fix in #89 works for me but how am I supposed to catch the error?

    I came up with this monster and it seems to be the best I can do:

            const client = new DBSQLClient({});
    
            let errorListener;
            let session: IDBSQLSession;
    
            // error handling is very cumbersome because the error is emitted after the
            // connect promise is resolved.
            try {
                session = await Promise.race([
                    new Promise<IDBSQLSession>((_, reject) => {
                        errorListener = (error: any) => {
                            reject(error);
                        };
                        client.on("error", errorListener);
                    }),
                    (async function (): Promise<IDBSQLSession> {
                        const connection = await client.connect(connectionOptions);
                        return connection.openSession();
                    })(),
                ]);
            } catch (e: any) {
                if (e.statusCode === 403) {
                    throw new Error(
                        "Invalid token. Please check your token and try again."
                    );
                } else {
                    throw e;
                }
            } finally {
                errorListener && client.removeListener("error", errorListener);
            }
  7. nisha-singh-tredence commented on Dec 27, 2022

    @nisha-singh-tredence

    I have also getting same bugs, Please help me to resolve this issue

  8. kravets-levko commented on Jan 25, 2023

    @kravets-levko
    Contributor

    v1.1.0 with the fix was released. Please try it, and feel free to report if you still have any issues. Thank you for patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions