Skip to content
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

DFS: Cache gen. timeout check only when needed #1436

Merged
merged 3 commits into from
Jul 12, 2019

Conversation

glye
Copy link
Member

@glye glye commented Jul 12, 2019

Only check cache generation timeout when generation has actually started, to avoid SQL error.

Calling DFSHandler::checkCacheGenerationTimeout() leads to an SQL error if cache generation hasn't started. In that case, the start timestamp is false which ends up as an empty string in the mysqli query. Fix this by not checking, when the timestamp is false. Also fixes CS.

Open questions:

  • Is the fact that this happens, a symptom for a bigger problem, or is it really just a long-lived bug?
  • Would it be more correct to fix this within checkCacheGenerationTimeout()? Done.

glye added 3 commits July 11, 2019 17:15
Only check cache generation timeout when generation has actually started. Avoids SQL error.
Only check cache generation timeout when generation has actually started. Avoids SQL error.
@glye glye requested a review from andrerom July 12, 2019 08:07
@andrerom andrerom requested a review from bdunogier July 12, 2019 09:15
Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks "ok" to me, bu I don't know this part that well so maybe @bdunogier can give some insights if this is ok as well.

@bdunogier
Copy link
Member

Is the fact that this happens, a symptom for a bigger problem, or is it really just a long-lived bug?

Yes.

+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++

To be honest, I'm not sure I can really help there any longer. Your analysis sounds correct, @glye. Semantically speaking, it would be both more correct and more meaningful to test this in a dedicated method. Instead of adding an has, I'd maybe rather test that $this->generationStartTimestamp isn't false in checkCacheGenerationTimeout().

@glye
Copy link
Member Author

glye commented Jul 12, 2019

Ack, moved to checkCacheGenerationTimeout() and added logging.

@glye glye merged commit 98b8f48 into master Jul 12, 2019
glye added a commit that referenced this pull request Jul 12, 2019
Only check cache generation timeout when generation has actually started. Avoids SQL error.
@gggeek
Copy link
Contributor

gggeek commented Jul 12, 2019

Mmm, what if cache generation was started by another process/thread? Would any piece of code call in that scenario checkCacheGenerationTimeout without generationStartTimestamp having been set ?

@bdunogier
Copy link
Member

bdunogier commented Jul 12, 2019

Actually, I would have returned false in that case, @glye. If we don't have a timestamp, we can't store, can we ?

glye added a commit that referenced this pull request Jul 12, 2019
@gggeek
Copy link
Contributor

gggeek commented Jul 12, 2019

It seems that the only entrypoint to this hairyball is towards the end of processCache(). So all of the executions should be internal to the class itself.

My question above then becomes: in which scenario does processCache call $this->storeCache (which uses the timeout value) without executing first through $this->startCacheGeneration() (which sets it) a few lines above?
I'd rather have someone take another look at the possible causes for this rather than applying this kind of blind patch...

ps: not having 'protected' and 'public' method modifiers makes control flow analysis of the codebase so much hareder... :-(

@glye
Copy link
Member Author

glye commented Jul 12, 2019

@gggeek It should afaik be reading the start timestamp from the shared db, but there could be a race condition where this sometimes doesn't work as expected.

@bdunogier checkCacheGenerationTimeout() returns true when cache generation did not time out, false when it did (cache generating stolen). If true (not timed out) then store() may try to store the cache. It's confusing. Anyway, if generation has not started it should be safe and sensible to try storing, right? That's why I return true.

@bdunogier
Copy link
Member

bdunogier commented Jul 12, 2019

I'd rather be very protective here @glye: we are in an unidentified case (race condition is a candidate indeed). I think that in that case, it is safe to generate the result, and not even try to store it. If several try to store at the same time, that's when more races occur.

Worst case, nobody does because of the race, and it will happen later.

Worstest case, nobody ever generates it...

++?????++ Out of Cheese Error. Redo From Start.

@glye
Copy link
Member Author

glye commented Jul 12, 2019

@gggeek Sorry, already merged before you joined in, and I'm leaving for 3 weeks. No releases likely in that time, anyway. But if you and @bdunogier agree on reverting, I'll do that.

@bdunogier
Copy link
Member

Maybe we should revert it until we have settled the discussion ?

@gggeek
Copy link
Contributor

gggeek commented Jul 12, 2019

I'll also be away from keyboard for 2 weeks :-D
Agree that on no-generation-started we should not try to store (btw what is the current behaviour? does the bad sql only generate a mysql warning or does it halt the whole page execution?).
Fine with revert...

glye added a commit that referenced this pull request Jul 12, 2019
@glye
Copy link
Member Author

glye commented Jul 12, 2019

Reverted.

@andrerom andrerom deleted the dfshandler_only_check_timeout_when_generation_started branch July 12, 2019 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants