-
Notifications
You must be signed in to change notification settings - Fork 677
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
fix race conditions causing notices if directory does not exist #8302
fix race conditions causing notices if directory does not exist #8302
Conversation
2dde842
to
233863d
Compare
Ready for code review & merge. Circle CI reported an error for a file I didn't modify, so I fixed that too, so tests wouldn't fail. |
It looks like this more reduces the probability of running into the race condition rather than actually fixing it. Can we just handle the error returned from failing operations instead? |
Race conditions in an independent multi-process environment are an unfixable issue in software in general, unless you want to slow everything down with locks (and even then you can get race conditions)
There already is an error, natively by PHP if any of that fails. And unfortunately, those errors are not actionable, bc there's nothing the user can do about it (well, the user could wait until 1 psalm process is finished before running the next, therefore having to wait ages longer) This PR fixed the race conditions we had in our use case, which is why I PRed it. I'm open for any suggestions on how to improve/reduce that code. |
Do we actually care about the errors though? Why not just ignore them? If all we care about is making sure a file is removed, instead of if (file_exists($file)) {
unlink($file);
} why not simply @unlink($file); ? I'd prefer to actually use try/catch and only catch errors due to the file not existing, but it doesn't seem like that's possible for this. Just ignoring all errors seems like it could be better than leaving the race condition there but reducing its likelihood. |
Bc this will snooze ALL errors. e.g. if unlink fails due to permission problems we will never know about it, bc @ snoozes that error. But we definitely need to know about this error, bc this can be fixed by the user. |
Good point, I wasn't sure if there were any errors we would care about, but a permission error is a good example of one we definitely want to show to the user. There's some discussion about the issue here, and a closed bug report here, unfortunately it doesn't seem as if there are any immediate plans to improve this in PHP. We might be able to use an example from the stackoverflow post to create a |
|
I suppose this is good enough for now then, maybe we can come back to it if PHP ever gives us better error handling for |
Seems fine :) Thanks! |
No description provided.