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

Container is sometimes being rebuilt on every request even though nothing changed #227

Closed
finwe opened this issue Aug 14, 2019 · 12 comments
Closed

Comments

@finwe
Copy link

finwe commented Aug 14, 2019

Version:

  • application: v3.0.1
  • bootstrap: v3.0.0
  • di: v3.0.1

Bug Description

According to Tracy Bar, the application sometimes falls to a state when the container is being rebuilt on every request.

This is a result of the condition $files !== $currentFiles in DependencyChecker::isExpired call being true. All compared files are equal except for temp/cache/nette.application/touch timestamp of which differs for about 2 seconds.

Steps To Reproduce

n/a. Unfortunately, this comes and goes and I haven't yet discovered the exact cause.

Expected Behavior

The container is being rebuit only when something actually changed.

Possible Solution

Compilation of the container takes about 500-1500 ms based on Tracy panel. Maybe the timestamps are saved on opposite sides of the compilation and therefore the difference?

@dg
Copy link
Member

dg commented Aug 15, 2019

These concurrent things are really mindblowing.

Just thinking… Could the cache play a role in this? Can you try call clearstatcache() before this line https://github.com/nette/di/blob/master/src/DI/DependencyChecker.php#L74 and/or before this line https://github.com/nette/di/blob/master/src/DI/DependencyChecker.php#L86?

@finwe
Copy link
Author

finwe commented Aug 15, 2019

Not really, I'm afraid.

After dev machine reboot and disabling xdebug, the container rebuild time is about 50ms and it is being rebuilt on about every second reload.

@mabar
Copy link
Contributor

mabar commented Aug 15, 2019

I am not sure if it's a best solution but these problems are related to https://github.com/nette/application/blob/master/src/Bridges/ApplicationDI/PresenterFactoryCallback.php#L47 and https://github.com/nette/application/blob/master/src/Bridges/ApplicationDI/ApplicationExtension.php#L152 PresenterFactoryCallback could not find presenter registered as a service and it triggers container rebuild, so you may have automatic registration of presenters misconfigured.
Most safe solution I found is replacement of callback with one which strictly requires presenter to be registered https://github.com/modette/modette/blob/master/packages/core-ext-ui/src/DI/PresenterFactoryCallback.php

@finwe
Copy link
Author

finwe commented Aug 15, 2019

@mabar You are probably right, yet I don't use any custom presenters registration - yes, presenters with scalar dependencies are registered manually in services config, but nothing custom apart from that.

@dg
Copy link
Member

dg commented Aug 15, 2019

Btw in the next bigger release I would like to move on to something like modette PresenterFactoryCallback and get rid of the dynamic creation of presenters.

@mabar
Copy link
Contributor

mabar commented Aug 15, 2019

Manual registration is totally ok, I have it as a enforced requirement. Problematic is autodiscovery - you may just forgot to add folder with your presenters to scanDirs. Or if you have scanComposer enabled then be aware of fact it can find only classes from classmap - PSR-4 namespaces are not searched

@mabar
Copy link
Contributor

mabar commented Aug 15, 2019

@dg ❤️ Glad to hear it

@finwe
Copy link
Author

finwe commented Aug 15, 2019

Presenters are loaded with robotLoader. Is simple robotloader configuration not enough? No scanDirs directive set, but looking to the source, scanDirs just sets the robotloader the same way.

@dg
Copy link
Member

dg commented Aug 15, 2019

Is simple robotloader configuration not enough?

No, because compiler has not access to RobotLoader, it must be configured via scanDirs.

@finwe
Copy link
Author

finwe commented Aug 15, 2019

Is that documented? When I remove $this->configurator->createRobotLoader() from my Bootstrap and add scanDirs to application in config.neon, presenter classes are not found.

Nette\DI\ServiceCreationException: Service '028': 
Class AdminModule\UploadPresenter not found

@finwe
Copy link
Author

finwe commented Aug 15, 2019

Oh, keeping both bootstrap robotLoader and scanDirs fixes this.

Couldn't this be easier? Will incorporating something like modette PresenterFactoryCallback solve this?

@dg
Copy link
Member

dg commented Aug 15, 2019

I tried to modify it to use an external robotloader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants