Restart offline pop_messages when there is mismatch between select and delete

When another connection is inserting something to spool at this same time
as we do pop_messages, it's possible that insert will happen between we
fetch messages and delete them, so we effectively will delete it without
delivering it to client. This change catch this situation and restart
transaction, so we should always have consistent results.
This commit is contained in:
Paweł Chmielowski 2020-04-17 15:30:28 +02:00
parent cb1c0a3188
commit 22980ed8a5
1 changed files with 10 additions and 4 deletions

View File

@ -267,9 +267,15 @@ get_and_del_spool_msg_t(LServer, LUser) ->
ejabberd_sql:sql_query_t(
?SQL("select @(username)s, @(xml)s from spool where "
"username=%(LUser)s and %(LServer)H order by seq;")),
ejabberd_sql:sql_query_t(
?SQL("delete from spool where"
" username=%(LUser)s and %(LServer)H;")),
Result
DResult =
ejabberd_sql:sql_query_t(
?SQL("delete from spool where"
" username=%(LUser)s and %(LServer)H;")),
case {Result, DResult} of
{{selected, Rs}, {updated, DC}} when length(Rs) /= DC ->
ejabberd_sql:restart(concurent_insert);
_ ->
Result
end
end,
ejabberd_sql:sql_transaction(LServer, F).