Skip to content

Commit b77cef5

Browse files
committed
Don't call mysql_close() when InactiveDestroy is set
Without this change, the END block of DBI would call disconnect_all() and that would call mysql_close() on all open connections. This is bad because forks would destroy their parent's context on exit as shown in the example for AutoInactiveDestroy in the DBI docs.
1 parent d7fbc30 commit b77cef5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

dbdimp.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,11 +2956,12 @@ mariadb_db_rollback(SV* dbh, imp_dbh_t* imp_dbh) {
29562956
return 1;
29572957
}
29582958

2959-
static void mariadb_dr_close_mysql(pTHX_ imp_drh_t *imp_drh, MYSQL *pmysql)
2959+
static void mariadb_dr_close_mysql(pTHX_ imp_drh_t *imp_drh, MYSQL *pmysql, bool actually_close)
29602960
{
29612961
if (pmysql)
29622962
{
2963-
mysql_close(pmysql);
2963+
if (actually_close)
2964+
mysql_close(pmysql);
29642965
imp_drh->instances--;
29652966
}
29662967
if (imp_drh->instances == 0)
@@ -3021,7 +3022,7 @@ static void mariadb_db_close_mysql(pTHX_ imp_drh_t *imp_drh, imp_dbh_t *imp_dbh)
30213022

30223023
if (imp_dbh->pmysql)
30233024
{
3024-
mariadb_dr_close_mysql(aTHX_ imp_drh, imp_dbh->pmysql);
3025+
mariadb_dr_close_mysql(aTHX_ imp_drh, imp_dbh->pmysql, DBIc_ACTIVE(imp_dbh));
30253026
imp_dbh->pmysql = NULL;
30263027
svp = hv_fetchs((HV*)DBIc_MY_H(imp_dbh), "ChildHandles", FALSE);
30273028
if (svp && *svp)
@@ -3059,6 +3060,8 @@ static void mariadb_db_close_mysql(pTHX_ imp_drh_t *imp_drh, imp_dbh_t *imp_dbh)
30593060
}
30603061
}
30613062
}
3063+
3064+
DBIc_ACTIVE_off(imp_dbh);
30623065
}
30633066

30643067
/*
@@ -3112,7 +3115,7 @@ int mariadb_dr_discon_all (SV *drh, imp_drh_t *imp_drh) {
31123115

31133116
while ((entry = imp_drh->taken_pmysqls))
31143117
{
3115-
mariadb_dr_close_mysql(aTHX_ imp_drh, (MYSQL *)entry->data);
3118+
mariadb_dr_close_mysql(aTHX_ imp_drh, (MYSQL *)entry->data, TRUE);
31163119
mariadb_list_remove(imp_drh->taken_pmysqls, entry);
31173120
}
31183121

0 commit comments

Comments
 (0)