mt-mods / mail

Mail mod for Luanti
https://content.minetest.net/packages/mt-mods/mail/
Other
14 stars 23 forks source link

Corrupt database caused by server crash without saving data properly #126

Closed nonfreegithub closed 6 months ago

nonfreegithub commented 10 months ago

When I receive more than 1 email, all of these appear in my inbox, but I can only read one of them, when I try to read another, the email body of the first one that I opened appears as the email body of all the other emails

example:

I receive 3 different emails from 3 different people with different subjects:

If I open mail 1, in the formspec GUI I read the body of mail 1. Now I open mail 2, and I see the body of mail 1.

If I restart the server, and check my inbox, I only see 1 email (mail 1), the others have disappeared!

I suspect this is because the database (pgsql mod storage) is corrupt, probably due to a forced restart of the server (for reasons unrelated to this mod) where the data was not saved correctly.

I assume there will be a lua table with some corrupted element:

local mails_table = {}

mails_table[1] = "mail1"
mails_table[2] = "mail2"
--mails_table[3] = "mail3" -- was corrupt, probably due to a forced restart of the server where the data was not saved correctly.
mails_table[4] = "mail4"
mails_table[5] = "mail5"

This is an example that I don't know if it helps or confuses.

In summary, I think that my email database in the mod storage is corrupted for reasons unrelated to this mod, and I think it could be fixed by adding something to the mod code without needing to delete my corrupt database

Athozus commented 10 months ago

That might be the 1 second storage update. @Bastrabun noticed an equivalent bug in #122 , with some different initial conditions. Thanks for giving a lot of information. I consider both issue as not the same, however my upcoming fix will probably fix both.

BuckarooBanzay commented 10 months ago

I suspect this is because the database (pgsql mod storage) is corrupt

somehow i doubt that :thinking: can you extract the relevant data from the database and post it here if possible?

nonfreegithub commented 10 months ago

can you extract the relevant data from the database and post it here if possible?

I could spend some time studying my database and separating what information could be relevant or not, I would have to learn to do that and how this mod stores the information in the database to know where and how to locate it.

I think it would take a lot of time

BuckarooBanzay commented 10 months ago

Maybe I could spend some time studying my database and separating what information could be relevant or not

someone else did the work for you:

# extract the json-value for the mail-entry in the modstorage
sqlite3 mod_storage.sqlite "select value from entries where modname = 'mail' and key = cast('mail/BuckarooBanzai' as blob);"

# (optional, but looks prettier) parse the output with `jq`
sqlite3 mod_storage.sqlite "select value from entries where modname = 'mail' and key = cast('mail/BuckarooBanzai' as blob);" | jq
nonfreegithub commented 10 months ago
sqlite3 mod_storage.sqlite "select value from entries where modname = 'mail' and key = cast('mail/BuckarooBanzai' as blob);"

nice! how can I do for postgresql?

BuckarooBanzay commented 10 months ago

nice! how can I do for postgresql?

right, i forgot this is possible now, here you go:

select convert_from(value, 'utf-8') from mod_storage where modname = 'mail' and key = 'mail/BuckarooBanzai';