amphp / parallel

An advanced parallelization library for PHP, enabling efficient multitasking, optimizing resource use, and application responsiveness through multiple CPU threads.
MIT License
779 stars 64 forks source link

Connection Timeout #124

Closed ckilb closed 1 year ago

ckilb commented 3 years ago

Code Formatted: https://pastebin.com/V8dAKU4n $promises = []; foreach ($items as $item) { $promises[] = Worker\enqueueCallable(function() use ($item, $productConcreteStorages, $productMerchantStorages) { return $this->mapItem($item, $productConcreteStorages, $productMerchantStorages); }); } $productViews = Promise\wait(Promise\all($promises));

Exception: `[previous exception] [object] (ErrorException(code: 0): stream_socket_accept(): accept failed: Connection timed out at /data/shop/development/current/vendor/amphp/parallel/lib/Context/Internal/ProcessHub.php:78) [stacktrace]

0 [internal function]: Spryker\Shared\ErrorHandler\ErrorHandlerEnvironment->Spryker\Shared\ErrorHandler\{closure}(2, 'stream_socket_a...', '/data/shop/deve...', 78, Array)

1 /data/shop/development/current/vendor/amphp/parallel/lib/Context/Internal/ProcessHub.php(78): stream_socket_accept(Resource id #1119, 0)

2 /data/shop/development/current/vendor/amphp/amp/lib/Loop/NativeDriver.php(183): Amp\Parallel\Context\Internal\ProcessHub::Amp\Parallel\Context\Internal\{closure}('a', Resource id #1119, NULL)

3 /data/shop/development/current/vendor/amphp/amp/lib/Loop/NativeDriver.php(96): Amp\Loop\NativeDriver->selectStreams(Array, Array, 4.976)

4 /data/shop/development/current/vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\Loop\NativeDriver->dispatch(true)

5 /data/shop/development/current/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()

6 /data/shop/development/current/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()

7 /data/shop/development/current/vendor/amphp/amp/lib/functions.php(229): Amp\Loop::run(Object(Closure))`

Any idea how to fix?

trowski commented 3 years ago

Can you disable the Spryker error handler and try again? It appears the error handler may not be honoring the current error reporting level and throwing an exception.

duckboy81 commented 3 years ago

Ran into the same issue with xdebugger ignoring the error suppression. See #125 for a potential fix.

duckboy81 commented 3 years ago

Can you disable the Spryker error handler and try again? It appears the error handler may not be honoring the current error reporting level and throwing an exception.

100% the error handler is the issue.

Just upgraded to 8.0 and came back here because my error handler needed updates to reflect the following breaking change: https://www.php.net/manual/en/migration80.incompatible.php

The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers that expect error_reporting to be 0 when @ is used, should be adjusted to use a mask check instead:

Saw a potential option for a future fix instead of just suppressing the E_WARNING https://github.com/walkor/Workerman/blob/master/Worker.php#L2463

\set_error_handler(function(){});
$new_socket = \stream_socket_accept($socket, 0, $remote_address);
\restore_error_handler();

Implemented here: https://github.com/amphp/parallel/compare/master...duckboy81:master

trowski commented 1 year ago

We've switched out uses of @ across all libraries compatible with AMPHP v3 to use a custom error handler to avoid mis-behaving error handlers.

For AMPHP v2, this is far from the only usage of @ and we are not planning on back-porting this "feature." As such, I'd recommend fixing any error handlers to properly check error_reporting().