Skip to content

Commit

Permalink
midb: resolve "inside a readonly TXN" warnings during message deletion
Browse files Browse the repository at this point in the history
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-2352
  • Loading branch information
jengelh committed Oct 2, 2024
1 parent a5398d3 commit 4a6189a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions exch/midb/mail_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4191,7 +4191,7 @@ static void mail_engine_modify_notification_message(
}

static void mail_engine_notification_proc(const char *dir,
BOOL b_table, uint32_t notify_id, const DB_NOTIFY *pdb_notify)
BOOL b_table, uint32_t notify_id, const DB_NOTIFY *pdb_notify) try
{
uint64_t parent_id = 0, folder_id = 0, message_id = 0;
char temp_buff[1280];
Expand Down Expand Up @@ -4240,8 +4240,12 @@ static void mail_engine_notification_proc(const char *dir,
auto stm = gx_sql_prep(pidb->psqlite, sql_string);
if (stm == nullptr || stm.step() != SQLITE_ROW)
return;
std::string name = znul(stm.col_text(0));
/* end implicit transaction since we have not attempted to read
* past the last row yet */
stm.finalize();
mail_engine_delete_notification_message(pidb.get(), folder_id,
message_id, pidb->username, stm.col_text(0));
message_id, pidb->username, name.c_str());
folder_id = 0;
break;
}
Expand Down Expand Up @@ -4275,8 +4279,10 @@ static void mail_engine_notification_proc(const char *dir,
auto stm = gx_sql_prep(pidb->psqlite, sql_string);
if (stm == nullptr || stm.step() != SQLITE_ROW)
return;
std::string name = znul(stm.col_text(0));
stm.finalize();
mail_engine_delete_notification_message(pidb.get(), folder_id,
message_id, pidb->username, stm.col_text(0));
message_id, pidb->username, name.c_str());
folder_id = n->folder_id;
message_id = n->message_id;
mail_engine_add_notification_message(pidb.get(), folder_id,
Expand Down Expand Up @@ -4309,10 +4315,14 @@ static void mail_engine_notification_proc(const char *dir,
auto stm = gx_sql_prep(pidb->psqlite, sql_string);
if (stm == nullptr || stm.step() != SQLITE_ROW)
return;
std::string name = znul(stm.col_text(0));
stm.finalize();
snprintf(temp_buff, std::size(temp_buff), "FOLDER-TOUCH %s %s",
pidb->username.c_str(), stm.col_text(0));
pidb->username.c_str(), name.c_str());
system_services_broadcast_event(temp_buff);
}
} catch (const std::bad_alloc &) {
mlog(LV_ERR, "E-2346: ENOMEM");
}

void mail_engine_init(const char *default_charset, const char *org_name,
Expand Down

0 comments on commit 4a6189a

Please sign in to comment.