Bug 178347 - FileSystem::deleteFile should log error status
Summary: FileSystem::deleteFile should log error status
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kate Cheney
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-10-16 10:26 PDT by Brent Fulgham
Modified: 2019-08-22 12:53 PDT (History)
16 users (show)

See Also:


Attachments
Patch (5.08 KB, patch)
2019-08-13 13:40 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (2.05 KB, patch)
2019-08-14 14:41 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (2.04 KB, patch)
2019-08-14 15:29 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff
Patch (2.06 KB, patch)
2019-08-14 16:54 PDT, Kate Cheney
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2017-10-16 10:26:51 PDT
It would be useful to know why the 'deleteFile' failed so that we could distinguish between multiple processes competing for a file lock, or bad permissions settings on the directories used by WebKit, etc.
Comment 1 Radar WebKit Bug Importer 2017-10-16 10:28:06 PDT
<rdar://problem/35008951>
Comment 2 Kate Cheney 2019-08-13 13:40:52 PDT
Created attachment 376209 [details]
Patch
Comment 3 Alexey Proskuryakov 2019-08-13 14:59:17 PDT
Comment on attachment 376209 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=376209&action=review

> Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp:865
> +                LOG_ERROR("Error deleting database file %s", file.utf8().data());

What are the privacy implications of logging file names?
Comment 4 Daniel Bates 2019-08-13 19:37:21 PDT
Comment on attachment 376209 [details]
Patch

Just passing by, can talk in person if you want advice.... I think this is your first bug, so good job on with picking up the process 🙂. Here are somethings that struck out at me when I glanced at this patch:

1. Logging is only at select call sites (I cannot tell if you’ve covered all call sites).
2. Logging is not in FileSystem::deleteFile, which I expected from the bug title.
3. You log things if deleteNonEmptyDirectory fails, which I didn’t expect from the bug title.
4. The logging does not include an error status, which I expected from the bug title.
5. The logging includes file names, which I didn’t expect from the bug title.
6. Alexey’s point
7. I think the logging is debug only and I’m unclear if that is a large enough audience for us to see thing.
8. I think this may be using the wrong logging mechanism: why not use log channels? ChangeLog message doesn’t explain.
9. ChangeLog message doesn’t explain how this logging makes things easier/what kinds of bugs we are trying to diagnose.
Comment 5 Kate Cheney 2019-08-14 14:41:58 PDT
Created attachment 376314 [details]
Patch
Comment 6 Brent Fulgham 2019-08-14 15:04:53 PDT
Comment on attachment 376314 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=376314&action=review

> Source/WTF/wtf/posix/FileSystemPOSIX.cpp:75
> +    bool unlinkResult = unlink(fsRep.data());

I would propose:

int unlinkResult = unlink(fsRep.data());

Or:

bool unlinked = !unlink(fsRep.data());
if (!unlinked)
    LOG_ERROR(....

return unlinked;
Comment 7 Kate Cheney 2019-08-14 15:29:59 PDT
Created attachment 376321 [details]
Patch
Comment 8 Alexey Proskuryakov 2019-08-14 16:14:38 PDT
Comment on attachment 376314 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=376314&action=review

> Source/WTF/wtf/posix/FileSystemPOSIX.cpp:70
> +        LOG_ERROR("Failed to get filesystem representation to create CString from cfString or filesystem representation is a null value");

I suggest prepending "File failed to delete. " or "Could not delete a file. " to this for some context.
Comment 9 Kate Cheney 2019-08-14 16:54:01 PDT
Created attachment 376332 [details]
Patch
Comment 10 Brent Fulgham 2019-08-14 17:05:02 PDT
Comment on attachment 376332 [details]
Patch

Looks good to me. r=me
Comment 11 WebKit Commit Bot 2019-08-14 18:58:12 PDT
Comment on attachment 376332 [details]
Patch

Clearing flags on attachment: 376332

Committed r248702: <https://trac.webkit.org/changeset/248702>
Comment 12 WebKit Commit Bot 2019-08-14 18:58:14 PDT
All reviewed patches have been landed.  Closing bug.
Comment 13 Tim Horton 2019-08-15 11:46:27 PDT
I'm hitting this a bunch locally... do you want bugs about cases where this logging happens, or what?
Comment 14 Kate Cheney 2019-08-15 14:27:14 PDT
(In reply to Tim Horton from comment #13)
> I'm hitting this a bunch locally... do you want bugs about cases where this
> logging happens, or what?

This doesn't need to be reported. It's for future bugs where the error might be meaningful in the context of the bug.
Comment 15 Darin Adler 2019-08-15 14:47:45 PDT
I think we might eventually need to do something different.

Sometimes something calls "deleteFile" and knows the file might not exist, and does not want that information logged to the console. If the failure is unexpected the logging is more useful. It would be nice to offer a way to log when the failure is unexpected only, even if this makes the code a tiny bit more complex.

Ideally we’d quiet the "hitting it a bunch locally" almost entirely with this technique, then we'd see logs for the unexpected failures.

Function calls that report their failures "directly to the user" are something I consider an anti-pattern. But I think we can cancel that out if we distinguish the expected failures from the unexpected ones.
Comment 16 Brent Fulgham 2019-08-15 16:24:16 PDT
(In reply to Tim Horton from comment #13)
> I'm hitting this a bunch locally... do you want bugs about cases where this
> logging happens, or what?

If this logging is getting spammy we might want to make it an INFO level log entry.

It would be interesting to know why the delete is failing, and whether it makes sense to call delete for that call stack, or whether we should be taking some action when the delete fails.

We might need to pass a flag indicating that failure is expected/normal in some cases, and not log when that happens.
Comment 17 Kate Cheney 2019-08-16 09:30:59 PDT
I could add a parameter to the deleteFile function that defaults to "never log." Then in the places where it is important (like the places I put the logging in the original patch upload, i.e. places where !FileSystem::deleteFile() is included in the code), I could set the parameter to "always log." Then any additional places we find along the way where logging might be helpful can also use the parameter as needed. Does that sound okay?
Comment 18 Darin Adler 2019-08-16 10:00:52 PDT
I think something like that is good. But maybe the default could go the other way. The callers that expect errors could indicate that they expect them.

However, I wouldn’t want the logging to ignore *all* errors, just the specific error that is expected. So the goal for the argument would be to say what error is expected.
Comment 19 Kate Cheney 2019-08-16 10:30:03 PDT
I agree. So, to summarize, the default would be to always log. Then the caller passes an argument to indicate any errors they expect that then won't be logged. 

One idea is the argument could be value(s) chosen from an enum of potential error codes of the unlink() function. I could also add in comments next to each code to ensure people know the correct code for the expected error, for ex, ENOENT is the "no such file or directory" error). If anyone has other ideas, I'd be happy to hear them too.
Comment 20 Darin Adler 2019-08-16 11:10:44 PDT
Yes, I think it should be an OptionSet of expected errors, but not literally POSIX errors like ENOENT since the point of FileSystem is to abstract away details of the operating system. So an OptionSet that expresses the types of errors that are expected, probably using an enumeration. We’d add them as we need new concepts.

I assume one value in the enumeration would be "it's OK if the file doesn't exist". Not sure which others we’d find we need.
Comment 21 Darin Adler 2019-08-16 11:11:21 PDT
Not exactly "expected errors" but "unsurprising errors, which we should ignore silently without logging".
Comment 22 Simon Fraser (smfr) 2019-08-22 12:53:57 PDT
Now every layout test logs:

12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)
12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)
12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)
12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)
12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)
12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)
12:46:33.026 12287   ERROR: File failed to delete. Error message: No such file or directory
12:46:33.026 12287   /Volumes/Data/Development/system/webkit/OpenSource/Source/WTF/wtf/posix/FileSystemPOSIX.cpp(77) : bool WTF::FileSystemImpl::deleteFile(const WTF::String &)