Skip to content

await client.openSession() unhandled error #77

Closed

Description

@wheelie33

I cannot find any solution to this issue when our cluster is 'inactive'. I also cannot find a way to test the connection status.

Additionally, it seems like the try catch isn't able to trap the error.

Activity

  1. kravets-levko commented on Oct 18, 2022

    @kravets-levko
    Contributor

    Hi @wheelie33! Can you please attach an output from your script so I can see the exact error?

  2. wheelie33 commented on Oct 18, 2022

    @wheelie33
    Author
    var token = process.env.DATABRICKS_TOKEN
    var serverHostname = process.env.DATABRICKS_SERVER_HOSTNAME
    var httpPath = process.env.DATABRICKS_HTTP_PATH
    
    app.get("/people", (_, res) => {
      try {
        let client = null
    
        client = new DBSQLClient()
    
        //const utils = DBSQLClient.utils
    
        client
          .connect(
            (options = {
              token: token,
              host: serverHostname,
              path: httpPath,
            })
          )
          .then(async (client) => {
          
    ### **_// this throws a 503 level error until the cluster is awake_**
            const session = await client.openSession()
    
            const queryOperation = await session.executeStatement(
              (statement = "SELECT * FROM default.people ORDER BY LastName"),
              (options = {
                runAsync: true,
                maxRows: 10000, // This option enables the direct results feature.
              })
            )
    
            const result = await queryOperation.fetchAll({
              progress: false,
              callback: () => {},
            })
    
            await queryOperation.close()
    
            res.send(result)
    
            await session.close()
            await client.close()
          })
    **_### // this doesn't get fired at all._**
          .catch((error) => {
            res.send(error)
          })
      } catch (error) {
        res.send(error)
      }
    })
  3. wheelie33 commented on Oct 18, 2022

    @wheelie33
    Author

    Here's the log for the unhandled exception

    Server is running on port 3001
    
    node:events:491
          throw er; // Unhandled 'error' event
          ^
    THTTPException: Received a response with a bad HTTP status code: 503
        at exports.HttpConnection.responseCallback (/Users/jason/SourceCode/mock_api/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:26)
        at ClientRequest.connection.responseCallback (/Users/jason/SourceCode/mock_api/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js:64:30)
        at Object.onceWrapper (node:events:628:26)
        at ClientRequest.emit (node:events:513:28)
        at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:674:27)
        at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
        at TLSSocket.socketOnData (node:_http_client:521:22)
        at TLSSocket.emit (node:events:513:28)
        at addChunk (node:internal/streams/readable:315:12)
        at readableAddChunk (node:internal/streams/readable:289:9)
    Emitted 'error' event on DBSQLClient instance at:
        at exports.HttpConnection.<anonymous> (/Users/jason/SourceCode/mock_api/node_modules/@databricks/sql/dist/DBSQLClient.js:68:22)
        at exports.HttpConnection.emit (node:events:513:28)
        at exports.HttpConnection.responseCallback (/Users/jason/SourceCode/mock_api/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js:173:12)
        at ClientRequest.connection.responseCallback (/Users/jason/SourceCode/mock_api/node_modules/@databricks/sql/dist/connection/connections/HttpConnection.js:64:30)
        [... lines matching original stack trace ...]
        at TLSSocket.emit (node:events:513:28) {
    
  4. kravets-levko commented on Oct 20, 2022

    @kravets-levko
    Contributor

    Hi @wheelie33! Thank you for logs and code example. I managed to reproduce this error, and once I find what causes it - I'll get back to you

  5. kravets-levko commented on Oct 20, 2022

    @kravets-levko
    Contributor

    @wheelie33 can you please also tell me which version of this connector you use? thank you!

  6. wheelie33 commented on Oct 20, 2022

    @wheelie33
    Author
  7. harinduliyanage commented on Nov 3, 2022

    @harinduliyanage

    This is due to the way you guys produce known exceptions you guys emit custom errors using node event emitter due to that catch handler couldn't able to catch this

    this.emit("error", new THTTPException(response)); // from databricks sdk source code

  8. kravets-levko commented on Nov 3, 2022

    @kravets-levko
    Contributor

    Hi @harinduliyanage! Can you please point me to exact line where you found that code fragment? Re. event emitter: TBH I don't like the fact we have use it, but some errors (like http errors) that come from Thrift library could be handled only this way - Thrift lib doesn't propagate that errors to corresponding request handler but instead just emits an event

  9. Sheing commented on Dec 4, 2022

    @Sheing

    @harinduliyanage @kravets-levko Did you guys figure out how to prevent THTTPException?

    This error sucks since it's inconsistent and hard to reproduce on my end.

    {"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)"}
    
  10. tonious commented on Dec 8, 2022

    @tonious

    I ran into a similar issue. In our application, a bad token resulted in openSession failing silently. For testing purposes, it may be easier to provoke a 403 error, and ensure that errors are handled or at least propagated. Here's a quick work around, but ymmv.

    const session = await (new Promise((resolve, reject) => {
      client
        .on('error', reject)
        .openSession()     
        .then(resolve);
    }));

    This uses a promise to capture the event from the event emitter. If an error occurs, the promise will reject and await will convert the rejection into an exception.

  11. kravets-levko commented on Aug 31, 2023

    @kravets-levko
    Contributor

    @wheelie33 do you still encounter this issue with newer library versions? Please let me know in either case. Thank you!

  12. kravets-levko commented on Jan 18, 2024

    @kravets-levko
    Contributor

    I'm closing this issue as in newer library versions we significantly improved error handling. Please feel free to re-open this issue if you still experience the same errors, or file a new issue if needed

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