eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.1k stars 2.4k forks source link

Database corruption caused by power loss #3159

Open marcinstrzelczyk opened 1 week ago

marcinstrzelczyk commented 1 week ago

Hello, I have mosquitto v2.0.18 running on Windows 10 as a service. Few days ago I experienced sudden power loss on my computer and then mosquitto failed to start with

Error: Unable to restore persistent database. Unrecognised file format.
Error: Couldn't open database.

errors in log file. Most likely mosquitto was trying to update the database file when the power loss happened, but I'm not 100% sure.

The mosquitto.db file exists and contains only NULLs. There is no mosquitto.db.new file, which I saw being mentioned in other issues.

This issue is similar to #189, I looked at PR for that issue and the solution was to add fflush(db_fptr); before closing the file (https://github.com/eclipse-mosquitto/mosquitto/pull/206/files), but it was done inside #ifndef WIN32 directive, so it was not applied to Windows version. I don't know if that fflush call could fix problems on Windows as well, but maybe it's worth looking at.

sitaalbeMarp commented 4 days ago

Hello, I've experienced similar behaviour also with version 2.0.20.