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

Uncaught Hoa\Socket\Client::_open(): (1) Client returns an error (number 111) #82

Open
michaellenahan opened this issue Sep 6, 2017 · 3 comments

Comments

@michaellenahan
Copy link
Contributor

On the time-server exercise, I get the following error when running:

$ learnyouphp verify time.php

time.php is the solution code from here: https://raw.githubusercontent.com/php-school/learn-you-php/master/exercises/time-server/solution/solution.php

PHP Fatal error:  Uncaught Hoa\Socket\Client::_open(): (1) Client returns an error (number 111): Connection refused while trying to join tcp://127.0.0.1:55019.
in /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/socket/Client.php at line 191.
  thrown in /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/socket/Client.php on line 191

Fatal error: Uncaught Hoa\Socket\Client::_open(): (1) Client returns an error (number 111): Connection refused while trying to join tcp://127.0.0.1:55019.
in /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/socket/Client.php at line 191.
  thrown in /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/socket/Client.php on line 191

Hoa\Socket\Exception\Exception: Client returns an error (number 111): Connection refused while trying to join tcp://127.0.0.1:55019. in /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/socket/Client.php on line 191

Call Stack:
    0.0002     360312   1. {main}() /home/michael/.php-school/workshops/learnyouphp/bin/learnyouphp:0
    0.0042     910536   2. PhpSchool\PhpWorkshop\Application->run() /home/michael/.php-school/workshops/learnyouphp/bin/learnyouphp:5
    0.0291    3934080   3. PhpSchool\PhpWorkshop\CommandRouter->route() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/Application.php:194
    0.0529    6942160   4. PhpSchool\PhpWorkshop\CommandRouter->resolveCallable() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/CommandRouter.php:131
    0.0668    7771184   5. PhpSchool\PhpWorkshop\CommandRouter->callCommand() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/CommandRouter.php:213
    0.0668    7771184   6. PhpSchool\PhpWorkshop\Command\VerifyCommand->__invoke() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/CommandRouter.php:233
    0.0668    7771184   7. PhpSchool\PhpWorkshop\ExerciseDispatcher->verify() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/Command/VerifyCommand.php:83
    0.1019    8329080   8. PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner->verify() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/ExerciseDispatcher.php:156
    0.1095    8369832   9. array_map() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/ExerciseRunner/CliRunner.php:143
    0.1095    8369888  10. PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner->PhpSchool\PhpWorkshop\ExerciseRunner\{closure}() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/ExerciseRunner/CliRunner.php:143
    0.1095    8369888  11. PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner->doVerify() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/ExerciseRunner/CliRunner.php:141
    0.1097    8376584  12. PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner->executePhpFile() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/ExerciseRunner/CliRunner.php:182
    0.1107    8383304  13. PhpSchool\PhpWorkshop\Event\EventDispatcher->dispatch() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/ExerciseRunner/CliRunner.php:97
    0.1107    8383304  14. PhpSchool\LearnYouPhp\Exercise\TimeServer->PhpSchool\LearnYouPhp\Exercise\{closure}() /home/michael/.php-school/workshops/learnyouphp/vendor/php-school/php-workshop/src/Event/EventDispatcher.php:44
    0.2144    8735696  15. Hoa\Socket\Client->connect() /home/michael/.php-school/workshops/learnyouphp/src/Exercise/TimeServer.php:80
    0.2145    8735744  16. Hoa\Socket\Client->__construct() /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/socket/Connection/Connection.php:197
    0.2150    8748304  17. Hoa\Socket\Client->open() /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/stream/Stream.php:172
    0.2150    8748304  18. Hoa\Stream\Stream::_getStream() /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/stream/Stream.php:290
    0.2151    8748744  19. Hoa\Socket\Client->_open() /home/michael/.php-school/workshops/learnyouphp/vendor/hoa/stream/Stream.php:213

@AydinHassan
Copy link
Member

Just tried locally and it works fine for me. Does it happen every time? I seem to recall there being some race conditions after opening the socket. Maybe you can try increasing https://github.com/php-school/learn-you-php/blob/master/src/Exercise/TimeServer.php#L78 to see if it fixes? Other than that I'm not really sure :/

@AydinHassan
Copy link
Member

We can definitely improve the experience by catching the exception and give a nicer error message. We could also retry on a different port if it fails the first time.

@michaellenahan
Copy link
Contributor Author

Thanks for responding!

"Does it happen every time?" Yes. I haven't tried it on another machine yet, I guess it must be something locally.

I have increased https://github.com/php-school/learn-you-php/blob/master/src/Exercise/TimeServer.php#L78 to 1000000, but that did not help.

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

2 participants