Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Statistics\DnsResolver may not inherit from final class #216

Closed
belzaaron opened this issue Jul 11, 2019 · 24 comments
Closed

Statistics\DnsResolver may not inherit from final class #216

belzaaron opened this issue Jul 11, 2019 · 24 comments

Comments

@belzaaron
Copy link

belzaaron commented Jul 11, 2019

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

@scbing
Copy link

scbing commented Jul 12, 2019

我也遇到相同错误。
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

@allowing
Copy link

image

@clugg
Copy link

clugg commented Jul 12, 2019

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.

@ehiaig
Copy link

ehiaig commented Jul 12, 2019

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.

@belzaaron
Copy link
Author

belzaaron commented Jul 12, 2019

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.

@ehiaig
Copy link

ehiaig commented Jul 12, 2019

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

@clugg
Copy link

clugg commented Jul 12, 2019

What worked for me is updating final class Resolver to class Resolver in the file vendor\react\dns\src\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.

@allowing
Copy link

low down to ^0.4 will be works

@ehiaig
Copy link

ehiaig commented Jul 13, 2019

What worked for me is updating final class Resolver to class Resolver in the file vendor\react\dns\src\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?

@ehiaig
Copy link

ehiaig commented Jul 13, 2019

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.

@TheBigK
Copy link

TheBigK commented Jul 16, 2019

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

@ash-jc-allen
Copy link

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.

@WyriHaximus
Copy link

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: reactphp/dns#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.

@WyriHaximus
Copy link

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

@ereztdev
Copy link

ereztdev commented Jul 29, 2019

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

@TheBigK
Copy link

TheBigK commented Jul 29, 2019

Right, I got the same error too!

@nea
Copy link

nea commented Jul 29, 2019

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

@peymanforceman
Copy link

Oh I got the same error today, and I fixed it with updating final class Resolver to class Resolver in the file vendor\react\dns\src\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. :(

@WyriHaximus
Copy link

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

@judahnator
Copy link

Any word on when a new tag will be released?

@devinfd
Copy link

devinfd commented Aug 6, 2019

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

@ragingdave
Copy link

this is resolved and can be closed with 1.2 right?

@clugg
Copy link

clugg commented Aug 25, 2019

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

@WyriHaximus
Copy link

Glad to hear that @clugg 🎉

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

No branches or pull requests