Skip to content

Commit

Permalink
Fix strand hanging when strand count exceeds BALLERINA_SQL_MAX_POOL_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedSabthar committed Oct 9, 2024
1 parent 8e98537 commit 8871e87
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
29 changes: 29 additions & 0 deletions ballerina/tests/query-row-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,35 @@ function queryRowEmptyTest2() returns error? {
test:assertEquals(result, expectedAlbum);
}

@test:Config {
groups: ["query", "query-row"]
}
function loadTestQueryRow() returns error? {
MockClient dbClient = check getMockClient(queryRowDb);
int strandCount = 60;
future<Album3|error>[] futures = [];
foreach int i in 0 ... strandCount {
future<Album3|error> 'future = start queryAlbum3(dbClient);
futures.push('future);
}
Album3 expectedAlbum = {
id: "2",
name: "Lemonade",
artist: (),
price: 20.0
};
foreach int i in 0 ... strandCount {
Album3 album = check wait futures.pop();
test:assertEquals(album, expectedAlbum);
}
check dbClient.close();
}

isolated function queryAlbum3(MockClient dbClient) returns Album3|error {
Album3 result = check dbClient->queryRow(`SELECT * FROM Album WHERE id_test = 2`);
return result;
}

isolated function validateDataTableRecordResult(record {}? returnData) {
decimal decimalVal = 23.45;
if returnData is () {
Expand Down
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
### Changed
- [Fix strand hanging when strand count exceeds BALLERINA_SQL_MAX_POOL_SIZE](https://github.com/ballerina-platform/ballerina-library/issues/7244)

## [1.13.2] - 2024-06-19

### Changed
- [Run database queries inside transaction block as non blocking query](https://github.com/ballerina-platform/ballerina-library/issues/6641)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package io.ballerina.stdlib.sql.datasource;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand All @@ -34,7 +34,7 @@ private SQLWorkerThreadPool() {

// This is similar to cachedThreadPool util from Executors.newCachedThreadPool(..); but with upper cap on threads
public static final ExecutorService SQL_EXECUTOR_SERVICE = new ThreadPoolExecutor(0, 50,
60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new SQLThreadFactory());
60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new SQLThreadFactory());

static class SQLThreadFactory implements ThreadFactory {
@Override
Expand Down

0 comments on commit 8871e87

Please sign in to comment.