Skip to content

Commit

Permalink
fix(jdbc-driver): Log errors from connection pool factory (#8903)
Browse files Browse the repository at this point in the history
generic-pool will just silently throw those away, so we should at least log them

Some supporting changes: 
* Set logger to simple console wrapper in driver tests
* Remove unused import
* Actually call connection.close in pool's destroy
  • Loading branch information
mcheshkov authored Nov 19, 2024
1 parent 0dbc499 commit cfdc2a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/cubejs-jdbc-driver/src/JDBCDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import { promisify } from 'util';
import genericPool, { Factory, Pool } from 'generic-pool';
import path from 'path';

import { DriverOptionsInterface, SupportedDrivers } from './supported-drivers';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { JDBCDriverConfiguration } from './types';
import { QueryStream, nextFn, Row, transformRow } from './QueryStream';
import { SupportedDrivers } from './supported-drivers';
import type { DriverOptionsInterface } from './supported-drivers';
import type { JDBCDriverConfiguration } from './types';
import { QueryStream, transformRow } from './QueryStream';
import type { nextFn } from './QueryStream';

/* eslint-disable no-restricted-syntax,import/no-extraneous-dependencies */
const DriverManager = require('@cubejs-backend/jdbc/lib/drivermanager');
Expand Down Expand Up @@ -147,8 +148,7 @@ export class JDBCDriver extends BaseDriver {
const getConnection = promisify(DriverManager.getConnection.bind(DriverManager));
return new Connection(await getConnection(this.config.url, this.jdbcProps));
},
// @ts-expect-error Promise<Function> vs Promise<void>
destroy: async (connection) => promisify(connection.close.bind(connection)),
destroy: async (connection) => promisify(connection.close.bind(connection))(),
validate: async (connection) => (
new Promise((resolve) => {
const isValid = promisify(connection.isValid.bind(connection));
Expand Down Expand Up @@ -183,6 +183,14 @@ export class JDBCDriver extends BaseDriver {
acquireTimeoutMillis: 120000,
...(poolOptions || {})
}) as ExtendedPool;

// https://github.com/coopernurse/node-pool/blob/ee5db9ddb54ce3a142fde3500116b393d4f2f755/README.md#L220-L226
this.pool.on('factoryCreateError', (err) => {
this.databasePoolError(err);
});
this.pool.on('factoryDestroyError', (err) => {
this.databasePoolError(err);
});
}

protected async getCustomClassPath() {
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-testing-drivers/src/helpers/getDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export async function getDriver(type: string): Promise<{
return import(`@cubejs-backend/${type}-driver`).then((module) => {
// eslint-disable-next-line new-cap
const source: BaseDriver = new module.default();
source.setLogger((msg: unknown, event: unknown) => console.log(`${msg}: ${JSON.stringify(event)}`));
const storage = new CubeStoreDriver();
return { source, storage };
});
Expand Down

0 comments on commit cfdc2a2

Please sign in to comment.