Laravel-websockets: Statistics\DnsResolver may not inherit from final class

Created on 11 Jul 2019  ·  24Comments  ·  Source: beyondcode/laravel-websockets

Hey! Love this project, greatly appreciate your time and effort!

However, I'm green-fielding a new project and we're going to use this package (again) for web-sockets. So the issue being, when attempting to run the websocket server (php artisan websockets:serve we are met by a nasty fatal error:

Symfony\Component\Debug\Exception\FatalErrorException  : Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)

This, I believe, is due to the recent https://github.com/reactphp/dns tag at v1.0.0. I am unfamiliar with the codebase so I do not have a commit id or pull request for this change. I'm just trying to put this out there. I'll do some digging soon-ish and see what I can find. But as of right now, a new project at Laravel:5.8.28 will have a fatal error running the socket server.

Thanks again and looking forward to collaborating to fix this :)

_edit to include full stack:_

PS D:\WebApps\squeegee> php artisan websockets:serve
PHP Fatal error:  Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver) in D:\WebApps\squeegee\vendor\beyondcode\laravel-websockets\src\Statistics\DnsResolver.php on line 8

   Symfony\Component\Debug\Exception\FatalErrorException  : Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)

  at D:\WebApps\squeegee\vendor\beyondcode\laravel-websockets\src\Statistics\DnsResolver.php:8
     4| 
     5| use React\Dns\Resolver\Resolver;
     6| use React\Promise\FulfilledPromise;
     7| 
  >  8| class DnsResolver extends Resolver
     9| {
    10|     /*
    11|      * This empty constructor is needed so we don't have to setup the parent's dependencies.
    12|      */


   Whoops\Exception\ErrorException  : Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)

  at D:\WebApps\squeegee\vendor\beyondcode\laravel-websockets\src\Statistics\DnsResolver.php:8
     4| 
     5| use React\Dns\Resolver\Resolver;
     6| use React\Promise\FulfilledPromise;
     7| 
  >  8| class DnsResolver extends Resolver
     9| {
    10|     /*
    11|      * This empty constructor is needed so we don't have to setup the parent's dependencies.
    12|      */

  Exception trace:

  1   Whoops\Run::handleError("Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)", "D:\WebApps\squeegee\vendor\beyondcode\laravel-websockets\src\Statistics\DnsResolver.php")
      D:\WebApps\squeegee\vendor\filp\whoops\src\Whoops\Run.php:433

  2   Whoops\Run::handleShutdown()
      [internal]:0

_edit to include commit that marked the class as final_

Commit that changed Resolver class to final

Most helpful comment

Confirming that I am also experiencing this issue. It seems to have been introduced with this commit. A temporary workaround is to forcibly downgrade react/dns in your composer.json: "react/dns": "^0.4.19", such that you are using a version where the classes are not marked as final.

All 24 comments

我也遇到相同错误。
I met the same mistake.

vendor\react\dns\src\Resolver\Resolver.php
at 11 line

final class Resolver
class Resolver

After replacement or rewriting, it seems that it can be solved.

run php artisan websockets:serve errors:

PHP Fatal error:  Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver) in /home/vagrant/websocket/vendor/beyondcode/laravel-websockets/src/Statistics/DnsResolver.php on line 8

   Symfony\Component\Debug\Exception\FatalErrorException  : Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)

  at /home/vagrant/websocket/vendor/beyondcode/laravel-websockets/src/Statistics/DnsResolver.php:8
     4| 
     5| use React\Dns\Resolver\Resolver;
     6| use React\Promise\FulfilledPromise;
     7| 
  >  8| class DnsResolver extends Resolver
     9| {
    10|     /*
    11|      * This empty constructor is needed so we don't have to setup the parent's dependencies.
    12|      */


   Whoops\Exception\ErrorException  : Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)

  at /home/vagrant/websocket/vendor/beyondcode/laravel-websockets/src/Statistics/DnsResolver.php:8
     4| 
     5| use React\Dns\Resolver\Resolver;
     6| use React\Promise\FulfilledPromise;
     7| 
  >  8| class DnsResolver extends Resolver
     9| {
    10|     /*
    11|      * This empty constructor is needed so we don't have to setup the parent's dependencies.
    12|      */

  Exception trace:

  1   Whoops\Run::handleError("Class BeyondCode\LaravelWebSockets\Statistics\DnsResolver may not inherit from final class (React\Dns\Resolver\Resolver)", "/home/vagrant/websocket/vendor/beyondcode/laravel-websockets/src/Statistics/DnsResolver.php")
      /home/vagrant/websocket/vendor/filp/whoops/src/Whoops/Run.php:433

  2   Whoops\Run::handleShutdown()
      [internal]:0

image

Confirming that I am also experiencing this issue. It seems to have been introduced with this commit. A temporary workaround is to forcibly downgrade react/dns in your composer.json: "react/dns": "^0.4.19", such that you are using a version where the classes are not marked as final.

I have this problem too. It started after I upgraded to Laravel5.8 since then I can't run php artisan websockets:serve. In an attempt to resolve it, I followed @clugg advice to downgrade "react/dns": "^0.4.19" of the required dependencies in composer.json and run composer update but this throws another error (in the image).

I don't know what else to do right now, can anyone help please?
Screenshot from 2019-07-12 12-47-59

I have this problem too. It started after I upgraded to Laravel5.8 since then I can't run php artisan websockets:serve. In an attempt to resolve it, I followed @clugg advice to downgrade "react/dns": "^0.4.19" of the required dependencies in composer.json and run composer update but this throws another error (in the image).
I don't know what else to do right now, can anyone help please?
Screenshot from 2019-07-12 12-47-59

@ehiaig maybe try to remove the /vendor/ folder and try the update. If that cannot be removed close all of your code editors/git clients/consoles and just start one instance of your console and try to remove /v/ then composer update again.

Thanks for your prompt response. I deleted the vendor folder and did composer update, but the problem remains.

I have this problem too. It started after I upgraded to Laravel5.8 since then I can't run php artisan websockets:serve. In an attempt to resolve it, I followed @clugg advice to downgrade "react/dns": "^0.4.19" of the required dependencies in composer.json and run composer update but this throws another error (in the image).

I don't know what else to do right now, can anyone help please?
Screenshot from 2019-07-12 12-47-59

@ehiaig maybe try to remove the /vendor/ folder and try the update. If that cannot be removed close all of your code editors/git clients/consoles and just start one instance of your console and try to remove /v/ then composer update again.

What worked for me is updating final class Resolver to class Resolver in the file vendor\react\dnssrc\Resolver\Resolver.php as suggested by @bing8u.

What worked for me is updating final class Resolver to class Resolver in the file vendor\react\dnssrc\Resolver\Resolver.php as suggested by @bing8u.

While this "works", it is incredibly poor practice to directly edit any code in your vendor directory (or any other directory managed by a dependency/package manager such as node_modules) for a couple of reasons, and I seriously would not recommend it.

  1. If you are not committing these changes to your repository (which you should not be, as vendor should be .gitignored) then other developers on the project will not have the changes, and as such will face the same issue you were facing. composer.lock exists such that others working on your project get the exact same dependencies as you when they run composer install - this isn't going to happen if you are changing the dependencies yourself.
  2. If you ever update the library in the future, your changes will disappear and you will have to manually reapply the change each time.

If composer update fails after updating your composer.json, generally the easiest fix is deleting the entire vendor directory and running it again.

In your case, that hasn't seemed to have worked. After deleting the vendor directory , can you confirm that it is in fact entirely gone? If not, an rm -rf vendor may be in order. Once the vendor directory is gone (and you're sure), composer install should work without a hitch, as your error relates to deleting an existing file which should no longer exist once it's parent directory is deleted.

low down to ^0.4 will be works

What worked for me is updating final class Resolver to class Resolver in the file vendor\react\dnssrc\Resolver\Resolver.php as suggested by @bing8u.

While this "works", it is incredibly poor practice to directly edit any code in your vendor directory (or any other directory managed by a dependency/package manager such as node_modules) for a couple of reasons, and I seriously would not recommend it.

1. If you are not committing these changes to your repository (which you should not be, as vendor should be .gitignored) then other developers on the project will not have the changes, and as such will face the same issue you were facing. composer.lock exists such that others working on your project get the _exact same_ dependencies as you when they run `composer install` - this isn't going to happen if you are changing the dependencies yourself.

2. If you ever update the library in the future, your changes will disappear and you will have to manually reapply the change each time.

If composer update fails after updating your composer.json, generally the easiest fix is deleting the entire vendor directory and running it again.

In your case, that hasn't seemed to have worked. After deleting the vendor directory , can you confirm that it is in fact entirely gone? If not, an rm -rf vendor may be in order. Once the vendor directory is gone (and you're sure), composer install should work without a hitch, as your error relates to deleting an existing file which should no longer exist once it's parent directory is deleted.

@clugg I am really grateful for your detailed response. I have deleted the vendor folder and done composer install yet no luck. Is there something I am doing wrong?

Confirming that I am also experiencing this issue. It seems to have been introduced with this commit. A temporary workaround is to forcibly downgrade react/dns in your composer.json: "react/dns": "^0.4.19", such that you are using a version where the classes are not marked as final.

Following this, it has been resolved by I adding "react/dns": "^0.4.19" to the "require-dev" dependencies in my composer.json.

Got the same error; and the suggested workaround did the job. How soon can I expect an official fix for this issue?

I have this problem too. It started after I upgraded to Laravel5.8 since then I can't run php artisan websockets:serve. In an attempt to resolve it, I followed @clugg advice to downgrade "react/dns": "^0.4.19" of the required dependencies in composer.json and run composer update but this throws another error (in the image).

I don't know what else to do right now, can anyone help please?
Screenshot from 2019-07-12 12-47-59

I have this problem too. It started after I upgraded to Laravel5.8 since then I can't run php artisan websockets:serve. In an attempt to resolve it, I followed @clugg advice to downgrade "react/dns": "^0.4.19" of the required dependencies in composer.json and run composer update but this throws another error (in the image).
I don't know what else to do right now, can anyone help please?
Screenshot from 2019-07-12 12-47-59

@ehiaig maybe try to remove the /vendor/ folder and try the update. If that cannot be removed close all of your code editors/git clients/consoles and just start one instance of your console and try to remove /v/ then composer update again.

Thanks for your prompt response. I deleted the vendor folder and did composer update, but the problem remains.

I have this problem too. It started after I upgraded to Laravel5.8 since then I can't run php artisan websockets:serve. In an attempt to resolve it, I followed @clugg advice to downgrade "react/dns": "^0.4.19" of the required dependencies in composer.json and run composer update but this throws another error (in the image).
I don't know what else to do right now, can anyone help please?
Screenshot from 2019-07-12 12-47-59

@ehiaig maybe try to remove the /vendor/ folder and try the update. If that cannot be removed close all of your code editors/git clients/consoles and just start one instance of your console and try to remove /v/ then composer update again.

I might be wrong, but you tend to get this problem if your user doesn't have the correct read/write permissions in Ubuntu. A quick way round this would be to do 'sudo composer update' rather than 'composer update'. It's not recommended to do this though because you're letting any install scripts run on your machine with root privileges. Best work around would be to make sure you've got the permissions for the folders/files you're working with.

Good morning, as you might have noticed we introduced several BC break in our latest major release of react/dns. One if witch you're now running into. That final keyword was introduced to discourage inheritance over composition.

Currently the best option for you to mitigate this at the short term is to require react/dns ^0.4.19 as @clugg suggested until this package has released a lorn term fix. Do not change your vendor files base with the next update or install that could change and you are back to square one.

Going forward there are two options:
a) v1.1.0 will introduce the ResolverInterface: https://github.com/reactphp/dns/pull/139
b) Create your own implementation of the ExecutorInterface which always resolves with 127.0.0.1.

For both options I strongly suggest requiring react/dns directly when you're using symbols from it. We'll always update our own packages to support our latest versions. Which often means widening version ranges supporting two version which contain BC breaks between them.

P.S. Next time just ping me when one of these issues arises with packages I'm involved with.

Suppose this have been solve now through #223 and #227?

nope, just downloaded and got this exact error on built. "beyondcode/laravel-websockets": "^1.1",

Right, I got the same error too!

Hi

I think a new release is still missing. So, yeah, it is solved with the given tickets and commits, but only in the master branch, as it is merged but not released atm.

Cheers

Oh I got the same error today, and I fixed it with updating final class Resolver to class Resolver in the file vendor\react\dnssrc\Resolver\Resolver.php as suggested by @bing8u and @ehiaig . but I believe it's not a good method because it's not a part of git push by default, so I hope for an update as soon as possible . this issue is really a big one. :(

You could temporarily require this package as dev-master or require react/dns as ^0.4 until a new release has been tagged here. Both aren't optimal solutions but they will do the trick

Any word on when a new tag will be released?

@mpociot any chance you could bump the version to include the latest merges? This bug is making laravel-websockets unusable on a new install.

this is resolved and can be closed with 1.2 right?

I can confirm that updating to 1.2 and removing the workaround (pinned reactdns dependency) is working perfectly for me.

Glad to hear that @clugg 🎉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

connecteev picture connecteev  ·  3Comments

stefandanaita picture stefandanaita  ·  4Comments

ElegantSoft picture ElegantSoft  ·  4Comments

darklight9811 picture darklight9811  ·  4Comments

rikless picture rikless  ·  4Comments