hunt-database icon indicating copy to clipboard operation
hunt-database copied to clipboard

PostgreSQL Connection not closing

Open vinoakash opened this issue 3 years ago • 2 comments

Hi All,

The below code is taken from the example provided in here, this code works, but the connection is not getting closed , "db.close" is not getting executed, and the program waits for ages.

` import std.stdio; import hunt.logging; import hunt.net.EventLoopPool; import hunt.concurrency.Future; import hunt.database; import std.datetime;

void main() { writeln("PostgreSQL demo."); string sql; int result; Statement statement; RowSet rs;

Database db = new Database("postgresql://admin:test123@localhost:5432/Dbtest");
SqlConnection sqlConn = db.getConnection();

Transaction transcation = sqlConn.begin(); sql = INSERT INTO public.Backup(Name) VALUES ('Test123');; tracef("transcation status: %s", transcation.status());

Future!RowSet promise = transcation.queryAsync(sql);
rs = promise.get(5.seconds);
tracef("Rows: \n%s", rs.toString());

import core.thread;
tracef("transcation status: %s", transcation.status());
transcation.commit();
tracef("transcation status: %s", transcation.status());

sqlConn.close();
tracef("status: %s", db.poolInfo()); // After this line it does not proceed further, struck at this line

db.close();
getchar();
shutdownEventLoopPool();
 getchar();

} `

vinoakash avatar Apr 23 '22 18:04 vinoakash

It should be suppended by getchar(). Comment out them.

Heromyth avatar Apr 26 '22 01:04 Heromyth

Even commenting the line "getchar();" the connection does not close `PostgreSQL demo. 2022-04-29 23:25:53 | 29192 | debug | main | transcation status: 0 | source\app.d:19 2022-04-29 23:25:53 | 29192 | debug | main | Rows: |

| source\app.d:23 2022-04-29 23:25:53 | 29192 | debug | main | transcation status: 1 | source\app.d:26 2022-04-29 23:25:53 | 29192 | debug | main | transcation status: 3 | source\app.d:28 2022-04-29 23:25:53 | 29192 | debug | main | status: Name: DbPool, Total: 5, Active: 0, Idle: 1, Free: 4, Waiters: 0 | source\app.d:31`

vinoakash avatar Apr 29 '22 15:04 vinoakash