Skip to content

Commit

Permalink
fix: drop SAP statement after prepare per Hana client docs
Browse files Browse the repository at this point in the history
each statement takes up a pool so if you query frequently you can
exhaust that pool of statement handles.  this drops the statement
after we're done with it so we don't exhaust the pool of statements
  • Loading branch information
imnotjames committed Jun 18, 2021
1 parent 7d614e9 commit 8350ba6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/driver/sap/SapQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
await Promise.all(otherWaitingPromises);
}

let statement: any;

const dropStatement = async () => {
await new Promise<void>((ok, fail) => {
if (!statement) {
ok();
}

statement.drop(() => ok());
})
}

const promise = new Promise(async (ok, fail) => {
try {
const databaseConnection = await this.connect();
Expand All @@ -190,7 +202,7 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
const queryStartTime = +new Date();
const isInsertQuery = query.substr(0, 11) === "INSERT INTO";

const statement = databaseConnection.prepare(query);
statement = databaseConnection.prepare(query);
statement.exec(parameters, (err: any, result: any) => {

// log slow queries if maxQueryExecution time is set
Expand Down Expand Up @@ -237,8 +249,8 @@ export class SapQueryRunner extends BaseQueryRunner implements QueryRunner {
});
} catch (err) {
fail(err);
}
});
}
}).then(dropStatement, dropStatement)

// with this condition, Promise.all causes unexpected behavior.
// if (this.isTransactionActive)
Expand Down

0 comments on commit 8350ba6

Please sign in to comment.