-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New unified favourites can disappear after game exit #4023
Comments
cc @kilbith |
@est31 Why are you pinging me ? I haven't touched the deleting mechanism. And even then, the mainmenu code (through |
Can this be reproduced before kilbith's change? |
I asked whether it can be. You modified it last which is why you're being pinged. I'm away from my computer so I can't check myself |
Don't know, I didn't use that feature before kilbith change :) |
If this is really Minetest's problem it must be a new one because when I tested it the first time I deleted my own |
Suspecting that my changes caused that is stupid. It has nothing to do with the mainmenu code and moreover with my changes. As I explained above, this piece of code has no capability to delete a file. I'm not yet sure that @est31 reproduced himself the bug before labelling as so.
The maincode does not modify the file in any way for displaying the list, except for deleting an entry. It uses its datas in the formspec but that's it, its integrity is always kept. Also note Fixer indicates a file deletion, not an emptying. |
@kilbith let people rule out your commit and then there is no question |
Still having this problem on 21079cc, lost favourites (entire file was deleted) after connecting to Xanadu server, not sure why and how. :/ It looks random, can lose it after connecting to server, or on game exit from serverbrowser. |
Trying to reproduce it on older build before kilbith PR. Can't reproduce yet. |
Added to milestones as is a possible blocker. |
What platforms was this observed on? I cannot reproduce this on Windows x64 build. |
Windows 7 sp1 64bit |
Still unreproducable apparently. |
More data now since I think I caught it in action. Debug.txt, suspected time of file deletion is 2016-04-26 21:21:34
|
I've taken a look at the log files. It's actually pretty funny. The intended logic is, create temp file, delete real file, rename temp file to real file. What actually happens is. Create temp file If you remove the application filter in ProcMon, you should see other applications use the file. Maybe a virus scanner? Windows file indexer? You don't need to reproduce the bug, you just need to see something else opens the file and you've proven this bug is possible. To prove this actually caused your specific issue you could check to make sure the actions happen in the order when you reproduce the bug. But I am, myself, satisfied. If this is the case, we probably need to rework the windows code. To be honest, I'm not sure what a good solution would involve. |
Well, as a start
if remove() does not return 0 then perhaps something should be logged (the errno at least)? Also if it fails (doesn't return 0) then it shouldn't really continue to try and rename the file which is going to fail because remove() failed[1], so some extra logic somehow needs to be added here. [1] Or does remove() on Windows actually just set a flag and indicate success? Is that what you're referring to @gregorycu? If that's what happens I wonder what checking if the file exists would return after the call to remove()... if the check does indicate that the file still exists perhaps everything could bail out at that point. Hypothetically, you'd then lose the temp file but not the existing file which is more important. Edit 2: Actually, perhaps something as simple as below is sufficient for something that seems to rarely happen anyway. IF it does start to occur more often we will also have a log entry to make finding this easier in future.
|
The issue isn't that remove fails, the issue is that the filesystem defers deletion of the file until all open handles are closed (including handles due to the search indexer, virus scanners etc.). In this exact case, remove would have returned 0, yet we would have still suffered the problem. Maybe we need to use ReplaceFile. |
That was my question, really. Is there any way to tell that Windows deferred the deletion? The Windows documentation, btw, says that remove() should return -1 if the file is already open
|
I've taken a look at the inner workings of remove, and it calls DeleteFile. https://msdn.microsoft.com/en-au/library/windows/desktop/aa363915%28v=vs.85%29.aspx
Emphasis mine. So, the documentation for remove is less than precise. |
I don't trust the documentation. A check for -1 would not hurt in any case (it actually should be there in the first place even if the bug remains). |
The check wouldn't really change anything. Just means we can warn when we fail to update the favourites in some circumstances (like someobody opened the file in notepad). Won't prevent favourites from being wiped in this case The documentation of DeleteFile appears to be consistent with Fixer's data from Process Monitor. |
The thing we really need to solve is wiping out the main file. We should fix the other cases too, but the first is a priority as there is nothing the user can do to avoid it. |
I guess what I'm wondering (and I cannot tell this from the documentation because as usual it's incomplete) is whether or not the return value of remove() indicates success even if the delete is deferred. Common sense says that yes it would, but whether or not that actually happens is another story. Even if it does still indicate success, surely Windows has a function to tell whether or not the remove/delete was deferred or not. Then again, maybe not. |
DeleteFile and thus remove will return 0, even in the case of deferred delete. From the perspective of the caller, flagging the file as "to be deleted" is mission accomplished. It has no idea when that will occur. In most cases, this will happen when the caller gives up its handle to the file. Even if it were to check the number of open handles on the file, that can change by the time we get to closing the file. We may be able to loop until the file actually gets deleted, but a simplier solution would be to use ReplaceFile. |
shrug use ReplaceFile then :) |
It's hard to believe that the Windows API behaves like that. It must cause bugs in millions of applications, but I will remove the "unconfirmed bug" in any case because I can see that the Windows-only code at least has issues (like not checking return values of functions) |
It's documented behaviour that would explain what we observed. We can ask Fixer to reproduce, though anyone on Windows with a virus scanner / search indexer should be able to. It's possible to write an app that will act just like a virus scanner and hold the file open for a while if you want to test the theory. |
Looks like the possible cause of the bug is conflict with foobar2000, which was monitoring minetest folder for music ^_^ (including favourites file). |
Should be fixed by c957346 |
Minetest Version: c350cfb and 21079cc
Bug:
Say you have 4 favourite servers, you join one, walk a bit, exit back to server list and decides to exit game completely (maybe even before server list is loaded). There is a high chance that you will lose your favourite servers, file disappears (deleted). I lost my favourites two or three times in one day.
You can lose it after logining to a server.
Try to join already only favourite servers to reproduce.
I don't know why file disappears but it connected to game exit. Please investigate as it can be confusing for noobs.
The text was updated successfully, but these errors were encountered: