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

Don't allow executing cli if cache backend is unavailable #25770

Merged
merged 1 commit into from
May 27, 2021

Conversation

st3iny
Copy link
Member

@st3iny st3iny commented Feb 23, 2021

Fix #25742

Bug

Currently, cli code can be executed even if the configured cache backend is unavailable. In this case, the cache factory is logging a warning instead of throwing an exception.

Problem: The cache factory is pulling a logger dependency which pulls the user manager and since #25440 it is pulling a cache factory. Now the the whole thing starts over and repeats until the process runs out of memory.

Solution

I propose the cli to fail if a cache backend is unavailable because some pieces of the server code expect a cache backend to be initialized in any case. Furthermore, there is an explicit warning regarding APCu setups in the admin documentation because it needs some extra configuration to be available in cli environments.

warning

Debugging

I added a print statement to ServerContainer.php/query() that prints the name of the requested dependency.

Here is an excerpt showing the recursion

Look for OC\Log -> OC\User\Manager -> OC\Memcache\Factory -> OC\Log -> ...

Querying OC\EventDispatcher\SymfonyAdapter
Querying OC\EventDispatcher\EventDispatcher
Querying Symfony\Component\EventDispatcher\EventDispatcher
Querying OCP\IServerContainer
Querying Psr\Log\LoggerInterface
Querying OC\Log\PsrLoggerAdapter
Querying OCP\ILogger
Querying OC\Log
Querying OC\AllConfig
Querying OC\SystemConfig
Querying OC\SystemConfig
Querying OCP\Support\CrashReport\IRegistry
Querying OC\Support\CrashReport\Registry
Querying OCP\IServerContainer
Querying OC\SystemConfig
Querying OCP\ILogger
Querying OC\Log
Querying OCP\EventDispatcher\IEventDispatcher
Querying OC\EventDispatcher\EventDispatcher
Querying OC\Files\Node\HookConnector
Querying OCP\Files\IRootFolder
Querying OCP\Lock\ILockingProvider
Querying bantu\IniGetWrapper\IniGetWrapper
Querying OCP\IConfig
Querying OC\AllConfig
Querying OCP\ICacheFactory
Querying OC\Memcache\Factory
Querying OCP\ILogger
Querying OC\Log
Querying OCP\IConfig
Querying OC\AllConfig
Querying OCP\IAppConfig
Querying OC\AppConfig
Querying OC\DB\Connection
Querying OC\SystemConfig
Querying OC\SystemConfig
Querying OCP\ILogger
Querying OC\Log
Querying OCP\Diagnostics\IQueryLogger
Querying OC\SystemConfig
Querying OC\SystemConfig
Querying OCP\ILogger
Querying OC\Log
Querying bantu\IniGetWrapper\IniGetWrapper
Querying bantu\IniGetWrapper\IniGetWrapper
Querying OCP\IRequest
Querying OCP\Security\ISecureRandom
Querying OC\Security\SecureRandom
Querying OCP\IConfig
Querying OC\AllConfig
Querying OC\Security\CSRF\CsrfTokenManager
Querying OC\Security\CSRF\CsrfTokenGenerator
Querying OCP\Security\ISecureRandom
Querying OC\Security\SecureRandom
Querying OC\Security\CSRF\TokenStorage\SessionStorage
Querying OCP\ISession
Querying OCP\IUserSession
Querying OC\User\Session
Querying OCP\IUserManager
Querying OC\User\Manager
Querying OCP\IConfig
Querying OC\AllConfig
Querying Symfony\Component\EventDispatcher\EventDispatcherInterface
Querying OC\EventDispatcher\SymfonyAdapter
Querying OCP\ICacheFactory
Querying OC\Memcache\Factory
Querying OCP\ILogger
Querying OC\Log
Querying OCP\IConfig
Querying OC\AllConfig
Querying OC\SystemConfig
Querying OCP\ILogger
Querying OC\Log
Querying bantu\IniGetWrapper\IniGetWrapper
Querying bantu\IniGetWrapper\IniGetWrapper
Querying OCP\IRequest
Querying OCP\Security\ISecureRandom
Querying OC\Security\SecureRandom
Querying OCP\IConfig
Querying OC\AllConfig
Querying OC\Security\CSRF\CsrfTokenManager
Querying OC\Security\CSRF\CsrfTokenGenerator
Querying OC\Security\CSRF\TokenStorage\SessionStorage
Querying OCP\ISession
Querying OCP\IUserSession
Querying OC\User\Session
Querying OCP\IUserManager
Querying OC\User\Manager
Querying OCP\IConfig
Querying OC\AllConfig
Querying Symfony\Component\EventDispatcher\EventDispatcherInterface
Querying OC\EventDispatcher\SymfonyAdapter
Querying OCP\ICacheFactory
Querying OC\Memcache\Factory
Querying OCP\ILogger
Querying OC\Log
Querying OCP\IConfig
Querying OC\AllConfig
Querying OC\SystemConfig
Querying OCP\ILogger
Querying OC\Log

This is a breaking change because occ and cron jobs won't be working anymore on some (misconfigured) ACPu setups. If someone can come up with a better solution or this is too much of a breaking change, feel free to close the PR.

@st3iny st3iny added bug 3. to review Waiting for reviews labels Feb 23, 2021
@st3iny st3iny self-assigned this Feb 23, 2021
@st3iny st3iny requested a review from nickvergessen February 23, 2021 18:31
@nickvergessen nickvergessen added the feature: caching Related to our caching system: scssCacher, jsCombiner... label Feb 23, 2021
@nickvergessen
Copy link
Member

Ah so now it all makes and I think the patch is fine

@kesselb
Copy link
Contributor

kesselb commented Feb 23, 2021

I guess we should drop support for APCu. cli does not share the cache with fpm/cgi/mod_php. This leads to weird results as web and cli may work with different data.

@nickvergessen
Copy link
Member

well it's a cache not a data store. but yeah could result in problems when e.g. web is trying to wipe it.

So let's add a setup deprecation warning for 22 and kill it in 23?

@kesselb
Copy link
Contributor

kesselb commented Feb 24, 2021

Thanks @st3iny for sending a patch 👍

Looks good to me. An alternative approach could be to check if apcu is configured + cli request and then return a null cache instance instead. For redis and memcache it's indeed a problem and unexpected behaviour if the cache is not available on cli. For apcu it's expected that the cache is not available on cli.

Still I'm not to happy about this change.

Querying OC\Log
Querying bantu\IniGetWrapper\IniGetWrapper
Querying bantu\IniGetWrapper\IniGetWrapper
Querying OCP\IRequest
Querying OCP\Security\ISecureRandom
Querying OC\Security\SecureRandom
Querying OCP\IConfig
Querying OC\AllConfig
Querying OC\Security\CSRF\CsrfTokenManager
Querying OC\Security\CSRF\CsrfTokenGenerator
Querying OCP\Security\ISecureRandom
Querying OC\Security\SecureRandom
Querying OC\Security\CSRF\TokenStorage\SessionStorage
Querying OCP\ISession
Querying OCP\IUserSession
Querying OC\User\Session
Querying OCP\IUserManager
Querying OC\User\Manager
Querying OCP\IConfig
Querying OC\AllConfig
Querying Symfony\Component\EventDispatcher\EventDispatcherInterface
Querying OC\EventDispatcher\SymfonyAdapter
Querying OCP\ICacheFactory
Querying OC\Memcache\Factory

We run into a loop on logging "Memcache {class} not available for {use} cache". The logger requests an instance of IRequest, for IRequest we need SecureRandom, IConfig and CsrfTokenManager, CsrfTokenManager needs SessionStorage, SessionStorage needs ISession. ISession needs IUserSession, IUserSession needs IUserManager, IUserManager needs ICacheFactory and all starts over again.

It's a bit sad that IRequest has so heavy dependencies. We could refactor passesCSRFCheck into a own service and make the Request object less heavy.

Another approach could be to move the user backend cache into a CachedUserManager wrapping the UserManager. But that comes with some other difficulties.

Of course. That's all to complicated to be backported 😞

@blizzz
Copy link
Member

blizzz commented Mar 26, 2021

web is trying to wipe it.

cli requests always start in a clear state. technically it might be an issue on long running processes when some stat has changed outside… but that's rather a distributed cache topic and apcu should not be used there.

@blizzz blizzz self-requested a review March 26, 2021 11:08
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

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

bkessel's concerns: #25770 (comment)

This was referenced May 20, 2021
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
@kesselb kesselb force-pushed the fix/25742/cli-cache-backend-recursion branch from 2d6f391 to 0f949ea Compare May 26, 2021 09:02
@kesselb kesselb added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels May 26, 2021
@blizzz blizzz merged commit 6f063c2 into master May 27, 2021
@blizzz blizzz deleted the fix/25742/cli-cache-backend-recursion branch May 27, 2021 15:56
@solracsf
Copy link
Member

Shouldn't this be backported?

@jkpirie

This comment has been minimized.

@szaimen
Copy link
Contributor

szaimen commented May 29, 2021

@skjnldsv backport to stable21?

@nickvergessen
Copy link
Member

Let me link to the discussion that recommended REMOVING the enable_cli from our documentation earlier:

If you have APCu configured and enable_cli off, Nextcloud will not work anymore on CLI with this PR.
Just for the record: this PR has been backported but is yet waiting to be released.

@tessus
Copy link

tessus commented Jun 22, 2021

With PHP7 and file-based caching, it can now make sense to enable opcache for CLI.

Yes, this is certainly possible from a performance perspective. However, you still have to take a few things into consideration. You don't run occ in a loop. Thus it is very likely that every time you start the script, the opcache entries in the file are too old and have to be recreated again. In this case you have 2 performance hits: 1) opcache has to be created every time (which takes time) 2) it takes even longer, because it is writing to a file instead of memory.
Also, you must use 2 separate ini files. You do not want to use opcache.file_cache_only=1 on your web server.
You really have to know what you are doing and according to the disussions and the last sentence of your comment, I really don't think many people do.

(So we had the recommendation, removed it, and now Nextcloud crashes servers that followed the 'new' recommendation. Whoopsie.)

Please, I really hope you don't consider not using opcache as the reason for Nextcloud crashing. The fact that it is disabled might bring another issue to light but it cannot be the root cause.
opcache is a feature of PHP, which makes sense since it is an interpreted language. It is not a requirement for PHP and it does not change the behavior of the language.
If something is crashing, it has nothing to do with opcache not being active. It's rather the other way around when there's a bug in opcache, which has actually happened a few times since opcache has been made available.

Please note that APCu and opcache are two completely different things. Please don't mix them up. APCu is also an optional feature of the language.

Update: Please note that I also replied to a question regarding file_cache 2 years ago: nextcloud/documentation#1439 (comment)

@tessus
Copy link

tessus commented Jun 22, 2021

If you have APCu configured and enable_cli off, Nextcloud will not work anymore on CLI with this PR.
Just for the record: this PR has been backported but is yet waiting to be released.

You can't be serious. Think what you are saying here. This PR must be reverted. You are trying to work around someting, but this is insane. You have to fix the root cause. You apparently don't understand how PHP works.
If you do this, you mask the real issue and it will bite all of us in the ass.

e.g. I have APCu configured, but I certainly do not enable it for cli. Because I actually know what I am doing. I am a performane expert. So now what? I can't use occ anymore?

I seriously doubt you understand the implications and I am amazed how illogical this approach is.

P.S.: I don't want to be hostile or harsh, but please think about what you are doing. This PR makes no sense. You don't have to believe me, you can talk to PHP developers or people who know how PHP works. This really shows me once again that design decisions are put into the wrong hands.

@MichaIng
Copy link
Member

MichaIng commented Jun 22, 2021

Yes guys, please don't mix OPcache with the config.php-wise configured memcache.local, that APCu can be.

For APCu it is since ages that the docs state via warning that it should be enabled for CLI calls, and disabling it, always triggered a log entry on each occ and cron.php call. But I agree that this was never a clever way to use APCu, respectively the configured memory cache, as, like stated above, it is intended to be a cache, not a data store.

The issue is that APCu can be easily (mis)used as data store, as it simply depends on the PHP script how it is read and written. And I agree that it makes much more sense to use it for what it is intended, as a cache that is used, when available for reading volatile data and else scripts must be able to generate this data freshly. And in case of writing data, if the configured memory cache is not available, a fallback to no cache (or custom SHM//tmp/database/something) would be great, especially for CLI calls, where this is reasonable anyway. And all data which are created by one script and consumed by other scripts (which are not able to generate it), require a data store, not a cache, so should be written to some temporary directory, the database or similar in the first place.

But hey, does it make sense to discuss all of this in a new issue? Currently this PR doesn't break anything for anyone, as, without it, the CLI call would still fail with current Nextcloud, or does it somehow still work for you @tessus?

EDIT: Another thing: While I agree that building an APCu cache for each CLI call doesn't make sense (generally, I don't know how it is currently used on detail), we're talking about some milli seconds here while all Nextcloud CLI calls I'm aware of take orders of magnitude longer to finish. So the actual downside of having APCu enabled for CLI calls is marginal, at least the way I faced it. Of course this may be different when the same PHP instance is used by other applications with much more frequent small CLI calls, where initiating the APCu significantly delays/slows down those or increases the server load in general in a significant way (also thinking about additionally reserved memory and such).

@tessus
Copy link

tessus commented Jun 22, 2021

I haven't upgraded nextcloud for a while, because new releases always break my working environment. My current setup works.

I am more than happy to dicuss this in a separate topic, but I am afraid the devs don't care. They misuse a cache and tell the world it's our fault, if we think that a cache should be a cache. There is nothing I can do to convince them otherwise. If bad design is the mantra of the developers I won't be able to change their minds. (I probably will get a ton of backlash for this comment, but it's a fact. It's not my fault, if overly sensitive people can't handle truth and facts.)

@MichaIng
Copy link
Member

MichaIng commented Jun 22, 2021

Okay so then this PR makes sense as a workaround until at least the loop introduced with #25440 has been fixed, or better a general fallback for CLI calls in the cache factory itself, when the cache is not available. Everything is better than an OOM-killed instance, e.g. in the middle of an upgrade.

Actually the code, prior to this commit, looks like it does quite what we want:

  • If no cache is available and it is a CLI call, set no cache.
  • Or is $localCacheClass = self::NULL_CACHE; not the same as when no cache (key not defined or value none) has been configured? (obviously not)
  • If so, wouldn't it then be best to simply override the config.php-configured caching backend with none/default when this condition (configured cache backend not available + CLI) is met?

@nickvergessen
Copy link
Member

nickvergessen commented Jun 22, 2021

I didn't check the docs link from Jos, I thought he linked to the APCu cli_enable one, so no mixup there from my side.

You are trying to work around someting, but this is insane.

Yes I am. I started caching something in the user backend (significantly reducing load) and it turns out to create an infinite loop in case APCu is configured but not available: because user backend > caching > logging > user backend > repeat
#25440

You have to fix the root cause.

I don't have enough time to fix the circular dependency in my free time.
It's questionable why caching should log something. (Nothing I did)
It's questionable why the logger depends on the user manager. (Nothing I did)
It's out of question that the user manager should be able to cache something. (Somthing I did which made everything go ham)

But I don't have time to untangle those, so I took the shorter route of pointing out the misconfiguration: "APCu configured but not available"
If that is meant to work someone can go ahead and send a PR and instead of failing insert the NullCache (as @MichaIng pointed out in parallel to my reply), fine by me.

If you do so please have a quick thought how from within a CLI/OCC/cron call a $cache->clear(); (and also remove at least) can be relayed so that APCu for non-CLI looses it's current cached values. If that is not intended we need to rethink the implementation of the cache system even deeper and maybe split in things that can be APCu cached and things that can not.

I don't want to be hostile or harsh, but please think about what you are doing. This PR makes no sense. You don't have to believe me, you can talk to PHP developers or people who know how PHP works. This really shows me once again that design decisions are put into the wrong hands.

🙄

@MichaIng
Copy link
Member

Thanks for clarifying and I agree that it is better to have such a workaround than the quite major issues users otherwise run into. To discuss a better solution I opened #27608. Interesting is, after having a deeper look into the code, that the old code seems to do exactly what I suggest. But then no loop would be possible, so obviously I am wrong. Would be great if you (whoever read this and is good in interpreting Nextcloud's PHP code) could have a look at it and point me to the misinterpretation I do, why the loop exists 🙂.

@tessus
Copy link

tessus commented Jun 22, 2021

I don't have enough time to fix the circular dependency in my free time.

What about all the paying customers? Don't you think they would consider this a priority?

What I don't understand is that this is an essential issue. It is part of the core design, yet you want to build a workaround.
Stop all new development and fix the core problems in Nextcloud. Why is that so hard to accomplish? You can't build a stable house on a broken foundation.
We've all seen how these workarounds turned out in other situations (file locking comes to mind).

I don't know why the devs always react negative when I point that out. Ignore me as the one with the problem right now. Just think of your business and your product. Forget the buts and ifs. You don't think it should be a priority to get the core design right and fix issues that are the result of either bad design or coding?

@kesselb
Copy link
Contributor

kesselb commented Jun 22, 2021

Interesting is, after having a deeper look into the code, that the old code seems to do exactly what I suggest. But then no loop would be possible, so obviously I am wrong. Would be great if you (whoever read this and is good in interpreting Nextcloud's PHP code) could have a look at it and point me to the misinterpretation I do, why the loop exists

@MichaIng #25770 (comment) the logger is causing the loop.

@MichaIng
Copy link
Member

How could I have overseen the explanation right there, thanks for for the anchor 👍.

Wouldn't it then be the easiest and obvious solution to first assign the NullCache (which is already done anyway) and then do the log afterwards?

		if (!class_exists($localCacheClass) || !$localCacheClass::isAvailable()) {
			if (\OC::$CLI && !defined('PHPUNIT_RUN')) {
				// CLI should not hard-fail on broken memcache but fallback to NullCache
				$localCacheClass = self::NULL_CACHE;
				$this->logger->info($missingCacheMessage, [
					'class' => $localCacheClass,
					'use' => 'local',
					'app' => 'cli'
				]);

So the logger can pull in another cache factory but it won't enter this condition again (class exists and isAvailable() always returns true for NullCache), breaking the loop?

@nickvergessen
Copy link
Member

nickvergessen commented Jun 23, 2021

As merged PRs are not the best place to discuss things,
please continue in #27608 so a solution can be shaped there.

@enoch85
Copy link
Member

enoch85 commented Jul 2, 2021

The Nextcloud VM broke down due to this PR (the backported one).

We run PHP-FPM, have all the stuff correct as per doumentation, but with 21.0.3 occ stopped working and in the end left servers in a panic state, since we depend so much on that occ works.

I'm quite baffled that you make such a large change without notice for a maintenance release.

I just merged a panic PR to revert to Redis for local cache, so problem solved. But still...

@MichaIng
Copy link
Member

MichaIng commented Jul 5, 2021

@enoch85
Just out of interest: Is there a specific reason why you do not enable APCu for CLI, as recommended in the docs for as long as I can think of? What are the downsides? Maybe you can contribute your thoughts here to have a real solution that either automatically falls back to NullCache (dummy cache backend) or even automatically uses NullCache in the first place on CLI calls, regardless of the configured cache.

@enoch85
Copy link
Member

enoch85 commented Jul 5, 2021

@MichaIng It was enabled but stopped working after this was merged.

As I didn't have time to investigate further, and a new release was made (several hundreds of downloads per day) I was in quite the panic to get this fixed. So basically, Redis worked, APCu didn't, hence the revert.

Though I agree that the best solution would be to actually run APCu for local cache, but since @kesselb mentioend this, I was like "ok, let's ditch it". I don't want to rely on something that might be ditched in 1 or even 10 versions. It should just work, no questions asked.

The alternative is to run without any cache at all, that would be really fool proof. But since I aim to give the Nextcloud VM users the best possible performance / stability, Redis it is for now at least.

@MichaIng
Copy link
Member

MichaIng commented Jul 5, 2021

Okay despite apc.enable_cli=1 it failed? That is strange indeed as then the condition affected by this PR should have never been met, respectively APCu for CLI already didn't work before. If old logs are present, an info log should then show up on every CLI call like "Memcache APCu not available for local cache" 🤔.

Though I agree that the best solution would be to actually run APCu for local cache

In general yes, but for CLI, reading through related discussions, it does not seem to make sense to initiate any cache for a single CLI call, after which it is in case destroyed again. So best IMHO, after reading through all related discussion, is to not use any cache in the first place for CLI calls. Redis, as dedicated server, of course allows a shared cache across all PHP instances, but I'm not sure whether it's worth it for CLI, as Redis otherwise is slower than APCu (?). Also I'm not sure whether cache keys are not otherwise instantiated anyway so that CLI calls cannot access the existing keys from the web/PHP-FPM server?

@enoch85
Copy link
Member

enoch85 commented Jul 6, 2021

Okay despite apc.enable_cli=1 it failed?

Yes indeed.

but I'm not sure whether it's worth it for CLI, as Redis otherwise is slower than APCu (?).

Yes, APCu is faster. Probably because the Redis traffic needs to travel a further distance than APCu, which is more nested into PHP.

Anyway, don't want to start a discussion here. We have now reverted to Redis which we used for several years in the VM and it works. So I see no reason to change back, especially since APCu seems to be depreciated in coming Nextcloud versions for PHP-FPM.

@MichaIng
Copy link
Member

MichaIng commented Jul 6, 2021

especially since APCu seems to be depreciated in coming Nextcloud versions for PHP-FPM

I don't think so, as it does not make any sense to remove support for the fasted local file cache solution, and relying on a shared cache would mean basically a misuse of a cache. I'll open a PR which disables local and distributed cache for all CLI calls in the first place, which after all I think is the only correct solution and makes all workarounds and apc.enable_cli=1 obsolete while keeping best performance for the website. I'm currently testing this locally.

But more discussion on that on the PR when it's up.

@kesselb kesselb mentioned this pull request Aug 15, 2023
5 tasks
MichaIng added a commit that referenced this pull request Jun 26, 2024
but fallback to NullCache. This can be the case if APCu is used without apc.enable_cli=1. APCu (and ArrayCache) however runs within the PHP instance and hence cannot be shared between CLI and web or used as distributed cache. The CLI call can hence only create or invalildate entries for itself. For short-living CLI calls, this is theoretically a downsides regarding performance and resource usage, and Nextcloud must not have any issues using the dummy NullCache instead of an isolated freshly created and destroyed APCu or ArrayCache instance.

This partly reverts #25770. The fallback was removed, because CLI calls started to hang after #25440. The reason however was not that a cache is generally required for CLI calls, but because the previously logged warning invoked the user backend, which invoked again the cacking backend, causing a loop.

This commit re-adds the fallback without logging a warning. For mentioned reasons, it is okay to fallback to NullCache silently.

The motivation is to make apc.enable_cli=1 optional, and that hence the documentation about it can be removed. We should not enforce admins to enable APCu for CLI calls, which is reasonably disabled by default. This also reduces requirements for hosting providers to support Nextcloud.

Signed-off-by: MichaIng <micha@dietpi.com>
MichaIng added a commit that referenced this pull request Jun 30, 2024
but fallback to NullCache. This can be the case if APCu is used without apc.enable_cli=1. APCu however runs within the PHP instance and hence cannot be shared between CLI and web or used as distributed cache. The CLI call can hence only create or invalidate entries for itself. For short-living CLI calls, this is theoretically a downsides regarding performance and resource usage, and Nextcloud must not have any issues using the dummy NullCache instead of an isolated freshly created and destroyed APCu instance.

This partly reverts #25770. The fallback was removed, because CLI calls started to hang after #25440. The reason however was not that a cache is generally required for CLI calls, but because the previously logged warning invoked the user backend, which invoked again the caching backend, causing a loop.

This commit re-adds the fallback without logging a warning, and for APCu only. For mentioned reasons, it is okay to fallback to NullCache silently. If Redis or memcached are configured but not available, then the web UI would fail as well, and it makes sense to abort and inform CLI calls as well then.

The motivation is to make apc.enable_cli=1 optional, and that hence the documentation about it can be removed. We should not enforce admins to enable APCu for CLI calls, which is reasonably disabled by default. This also reduces requirements for hosting providers to support Nextcloud.

Signed-off-by: MichaIng <micha@dietpi.com>
MichaIng added a commit that referenced this pull request Jun 30, 2024
but fallback to NullCache. This can be the case if APCu is used without apc.enable_cli=1. APCu however runs within the PHP instance and hence cannot be shared between CLI and web or used as distributed cache. The CLI call can hence only create or invalidate entries for itself. For short-living CLI calls, this is theoretically a downsides regarding performance and resource usage, and Nextcloud must not have any issues using the dummy NullCache instead of an isolated freshly created and destroyed APCu instance.

This partly reverts #25770. The fallback was removed, because CLI calls started to hang after #25440. The reason however was not that a cache is generally required for CLI calls, but because the previously logged warning invoked the user backend, which invoked again the caching backend, causing a loop.

This commit re-adds the fallback without logging a warning, and for APCu only. For mentioned reasons, it is okay to fallback to NullCache silently. If Redis or memcached are configured but not available, then the web UI would fail as well, and it makes sense to abort and inform CLI calls as well then.

The motivation is to make apc.enable_cli=1 optional, and that hence the documentation about it can be removed. We should not enforce admins to enable APCu for CLI calls, which is reasonably disabled by default. This also reduces requirements for hosting providers to support Nextcloud.

Signed-off-by: MichaIng <micha@dietpi.com>
MichaIng added a commit that referenced this pull request Jul 3, 2024
but fallback to NullCache. This can be the case if APCu is used without apc.enable_cli=1. APCu however runs within the PHP instance and hence cannot be shared between CLI and web or used as distributed cache. The CLI call can hence only create or invalidate entries for itself. For short-living CLI calls, this is theoretically a downsides regarding performance and resource usage, and Nextcloud must not have any issues using the dummy NullCache instead of an isolated freshly created and destroyed APCu instance.

This partly reverts #25770. The fallback was removed, because CLI calls started to hang after #25440. The reason however was not that a cache is generally required for CLI calls, but because the previously logged warning invoked the user backend, which invoked again the caching backend, causing a loop.

This commit re-adds the fallback without logging a warning, and for APCu only. For mentioned reasons, it is okay to fallback to NullCache silently. If Redis or memcached are configured but not available, then the web UI would fail as well, and it makes sense to abort and inform CLI calls as well then.

The motivation is to make apc.enable_cli=1 optional, and that hence the documentation about it can be removed. We should not enforce admins to enable APCu for CLI calls, which is reasonably disabled by default. This also reduces requirements for hosting providers to support Nextcloud.

Signed-off-by: MichaIng <micha@dietpi.com>
AndyScherzinger pushed a commit that referenced this pull request Aug 1, 2024
but fallback to NullCache. This can be the case if APCu is used without apc.enable_cli=1. APCu however runs within the PHP instance and hence cannot be shared between CLI and web or used as distributed cache. The CLI call can hence only create or invalidate entries for itself. For short-living CLI calls, this is theoretically a downsides regarding performance and resource usage, and Nextcloud must not have any issues using the dummy NullCache instead of an isolated freshly created and destroyed APCu instance.

This partly reverts #25770. The fallback was removed, because CLI calls started to hang after #25440. The reason however was not that a cache is generally required for CLI calls, but because the previously logged warning invoked the user backend, which invoked again the caching backend, causing a loop.

This commit re-adds the fallback without logging a warning, and for APCu only. For mentioned reasons, it is okay to fallback to NullCache silently. If Redis or memcached are configured but not available, then the web UI would fail as well, and it makes sense to abort and inform CLI calls as well then.

The motivation is to make apc.enable_cli=1 optional, and that hence the documentation about it can be removed. We should not enforce admins to enable APCu for CLI calls, which is reasonably disabled by default. This also reduces requirements for hosting providers to support Nextcloud.

Signed-off-by: MichaIng <micha@dietpi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug feature: caching Related to our caching system: scssCacher, jsCombiner...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NC 21] OCC Update error: allowed memory size exhausted