nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.47k stars 280 forks source link

FetchError due to Premature close! #4308

Closed kumarav16 closed 2 months ago

kumarav16 commented 10 months ago

Details

we encountered the below error while trying to run multiple queries i.e., more than 60 queries concurrently with databricks.

FetchError: Invalid response body while trying to fetch https://adb-4989540552326160.0.azuredatabricks.net/sql/1.0/warehouses/d332f02ce1613e30: Premature close.

NOTE : when we tried downgrading the node version from 20 to 16 it worked perfectly fine, even it supported for more that 1000 query concurrently.

Node.js version

20.10.0

Example code

const DbInterface = require('./dbInterface')
const { DBSQLClient } = require('@databricks/sql');
const dotenv = require("dotenv").config();
const localConfig = require('../../localConfig')
const logger = require('../logger').logger;

const TENANT_INFO = process.env.TENANT_INFO ? JSON.parse(process.env.TENANT_INFO) : localConfig;
let retryCount = TENANT_INFO.RETRYCOUNT;

const client = new DBSQLClient();
const connectOptions = {
  token: process.env.DATABRICKS_TOKEN,
  host: TENANT_INFO.DATABRICKS_SERVER_HOSTNAME,
  path: TENANT_INFO.DATABRICKS_HTTP_PATH
};

class DatabricksConnection extends DbInterface {
  constructor() {
    super();
    this.connection = null;
  }

  async openConnection() {
    try{
      let newClient = await client.connect(connectOptions);
      logger.info('Connecting Successfully to databricks!!',newClient.client);
      this.connection = newClient;
      return newClient;
    }catch(err){
      logger.info(`error occurred while opening DB connection, ${err}`);
      throw err;
    }

  }

  async executeQuery(newQuery) {
    let session;
    let queryOperation;
    try{
       session = await this.startSession(this.connection,retryCount);
       queryOperation = await session.executeStatement(
      newQuery,
      {
        runAsync: true
      }
    );
    const result = await queryOperation.fetchAll();
    await queryOperation.close();
    await this.endSession(session);
    return result;
    }catch(error){
      logger.info(`error occurred while executing the BD query, ${error}`);
      throw error;
    }
  }

  async startSession(clientDB,retryCount) {
    try{
      const session = await clientDB.openSession();
      return session;
    }catch(err){
      logger.error(`Error while re-try in open connection :${err}`);
      let count = retryCount - 1;
      if(count >= 0 ){
        logger.info(`retry count is- ${count}`);
        await this.startSession(this.connection,count)
      }
      throw err;
    }

  }

  async endSession(session) {
    try{
      await session.close();
    }catch(error){
      logger.info(`Error occurred while closing session, ${error}`)
    }

  }

  async closeConnection(client) {
    try{
      await client.close();
    }catch(error){
      logger.info(`Error occurred while closing connection, ${error}`)
    }
  }

}

module.exports = {DatabricksConnection,client};

Operating system

Microsoft Windows 10 Enterprise

Scope

runtime

Module and version

20.10.0

github-actions[bot] commented 3 months ago

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] commented 2 months ago

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.