Skip to content

Commit b7d93e7

Browse files
committed
midb: resolve "inside a readonly TXN" warnings during message deletion
An implicitly started transaction stays open until the cursors have reached the end of the data set. Just like e.g. fread(3), it is not sufficient to read the exact number of rows/bytes — it really takes that final step()/fread() call for the end-of-data/end-of-file flag to be set. Fixes: gromox-2.17-23-g24e7d57eb Fixes: gromox-2.17-117-g5fb5e9a20 References: GXL-524, GXF-1738, GXF-1769, DESK-2301, DESK-2311 References: DESK-2402, DESK-2421, DESK-2436, DESK-2449
1 parent a5398d3 commit b7d93e7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

exch/midb/mail_engine.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -4191,7 +4191,7 @@ static void mail_engine_modify_notification_message(
41914191
}
41924192

41934193
static void mail_engine_notification_proc(const char *dir,
4194-
BOOL b_table, uint32_t notify_id, const DB_NOTIFY *pdb_notify)
4194+
BOOL b_table, uint32_t notify_id, const DB_NOTIFY *pdb_notify) try
41954195
{
41964196
uint64_t parent_id = 0, folder_id = 0, message_id = 0;
41974197
char temp_buff[1280];
@@ -4240,8 +4240,12 @@ static void mail_engine_notification_proc(const char *dir,
42404240
auto stm = gx_sql_prep(pidb->psqlite, sql_string);
42414241
if (stm == nullptr || stm.step() != SQLITE_ROW)
42424242
return;
4243+
std::string name = znul(stm.col_text(0));
4244+
/* end implicit transaction since we have not attempted to read
4245+
* past the last row yet */
4246+
stm.finalize();
42434247
mail_engine_delete_notification_message(pidb.get(), folder_id,
4244-
message_id, pidb->username, stm.col_text(0));
4248+
message_id, pidb->username, name.c_str());
42454249
folder_id = 0;
42464250
break;
42474251
}
@@ -4275,8 +4279,10 @@ static void mail_engine_notification_proc(const char *dir,
42754279
auto stm = gx_sql_prep(pidb->psqlite, sql_string);
42764280
if (stm == nullptr || stm.step() != SQLITE_ROW)
42774281
return;
4282+
std::string name = znul(stm.col_text(0));
4283+
stm.finalize();
42784284
mail_engine_delete_notification_message(pidb.get(), folder_id,
4279-
message_id, pidb->username, stm.col_text(0));
4285+
message_id, pidb->username, name.c_str());
42804286
folder_id = n->folder_id;
42814287
message_id = n->message_id;
42824288
mail_engine_add_notification_message(pidb.get(), folder_id,
@@ -4309,10 +4315,14 @@ static void mail_engine_notification_proc(const char *dir,
43094315
auto stm = gx_sql_prep(pidb->psqlite, sql_string);
43104316
if (stm == nullptr || stm.step() != SQLITE_ROW)
43114317
return;
4318+
std::string name = znul(stm.col_text(0));
4319+
stm.finalize();
43124320
snprintf(temp_buff, std::size(temp_buff), "FOLDER-TOUCH %s %s",
4313-
pidb->username.c_str(), stm.col_text(0));
4321+
pidb->username.c_str(), name.c_str());
43144322
system_services_broadcast_event(temp_buff);
43154323
}
4324+
} catch (const std::bad_alloc &) {
4325+
mlog(LV_ERR, "E-2346: ENOMEM");
43164326
}
43174327

43184328
void mail_engine_init(const char *default_charset, const char *org_name,

0 commit comments

Comments
 (0)