roadrunner-server / roadrunner

🤯 High-performance PHP application server, process manager written in Go and powered with plugins
https://docs.roadrunner.dev
MIT License
7.91k stars 413 forks source link

[🐛 BUG]: kv plugin: isAvailable() doesn't work #901

Closed arku31 closed 2 years ago

arku31 commented 2 years ago

No duplicates 🥲.

What happened?

According to docs, you may check that kv plugin is present

$factory = new Factory(RPC::create('tcp://127.0.0.1:6001'));

if (!$factory->isAvailable()) {
    throw new \LogicException('The "kv" RoadRunner plugin not available');
}

But it always leads to the error

Fatal error: Uncaught LogicException: The "kv" RoadRunner plugin not available in ...

If you remove this check and try to access kv directly, it is working without issues.

Version

2.6.3

config:

rpc:
  listen: tcp://0.0.0.0:6001

server:
  command: "php public/worker.php"

http:
  address: "0.0.0.0:8081"
kv:
  memory:
    driver: memory
    config:
      interval: 1

Relevant log output

./rr serve
2021-12-30T12:54:53.135+0100    DEBUG   rpc             RPC plugin started      {"address": "tcp://0.0.0.0:6001", "plugins": ["informer", "resetter", "kv"]}
[INFO] RoadRunner server started; version: 2.6.6, buildtime: 2021-12-15T10:32:58+0000
2021-12-30T12:54:53.507+0100    INFO    server          
Fatal error: Uncaught LogicException: The "kv" RoadRunner plugin not available in
rustatian commented 2 years ago

Hey @arku31, thanks for the report. You can safely (temporarily) remove this check. That's because the RR and PHP-Worker approach to check available plugins had been changed recently and weren't synced recently.

brgmn commented 2 years ago

Hey, I just had a hard time to debug this behaviour: The isAvailable()-method in the php roadrunner-kv library seems to stopped working for roadrunner > v.2.6.2. Maybe it makes sense to just update the documentation or fix roadrunner to output the kv module as available module again. Btw the kv module works fine over rpc.

rustatian commented 2 years ago

@brgmn Hey. Sorry for the bad UX 😭 . Yeah, you may just remove this call. We will resolve this in the v2.9.0. We need to decide how to provide an available plugins list to the PHP, so, basically, there are 2 options:

  1. Remove this method (the cons that you'll know that the KV isn't available on the first call to it, but not on the boot time)
  2. Provide a list of plugins to the PHP worker via some internal RPC service bus. The cons here is that can cause problems on some systems where these RPC ports could be blocked by the firewall for example. So, we definitely working on providing a better option, but, that may take some time.
brgmn commented 2 years ago

@rustatian Ok. Nice! Thanks for your fast response and your great work! And do you think it would make sense to update the Readme and documentation of the roadrunner-kv php package that isAvailable doesn't work for roadrunner >v.2.6.2?

Btw I'm just using roadrunner as nginx-fpm replacement and the usecase I'm trying to solve is to warmup roadrunner kv-caches asynchronously by normal laravel events/workers running outside of roadrunner (e.g. when eloquent objects are updated). My goal is to always have warm caches in all roadrunner requests/workers. But maybe I'll have to write a dedicated varnish-like middleware for roadrunner (including cache-tags, etc). Anyways: my first tests with the kv module look really promising.

rustatian commented 2 years ago

@brgmn You are welcome 🚀

But maybe I'll have to write a dedicated varnish-like middleware for roadrunner (including cache-tags, etc).

We already have this on the roadmap link. Some of the proposals are partly implemented via cache middleware (RFC 7234, Cache-Control, Age, max-age via in-memory storage and only for the GET requests).

To warm up caches you may use the on_init server option (if that is suitable): https://github.com/roadrunner-server/roadrunner/blob/master/.rr.yaml#L28. The command in this option is not necessary a worker. It can be any PHP/bash/bat script or even any binary 😃

EDIT: The on_init script will be fired before the workers are allocated.

rustatian commented 2 years ago

And do you think it would make sense to update the Readme and documentation of the roadrunner-kv php package that isAvailable doesn't work for roadrunner >v.2.6.2?

Yeah, sure, will do that.

rustatian commented 2 years ago

And do you think it would make sense to update the Readme and documentation of the roadrunner-kv php package that isAvailable doesn't work for roadrunner >v.2.6.2?

Yeah, sure, will do that.

Done.

rustatian commented 2 years ago

Done, removed/deprecated this method everywhere 😃