-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Improve error reporting when incorrectly using await()
(Value of type null is not callable in src/SimpleFiber.php:66)
#50
Comments
Hey @greendrake |
await()
(Value of type null is not callable in src/SimpleFiber.php:66)
I am having the same error: Does anyone have the solution code to share? |
@mowses can you share any code that triggers this? |
Update: right now I am reading your blog at https://blog.wyrihaximus.net/2021/12/async-and-await-at-the-edge-with-reactphp/ @WyriHaximus sure. I am testing my
<?php
namespace Modules\Lobby\Tests\Unit\Sockets;
class ConnectionTest extends SocketTestCase
{
public function test_debugging_error()
{
$this->startServer(function () {
$this->connect("/app/INVALID-APP-KEY/room/INVALID-ROOM-ID", function () {
dump('connection #1');
$this->assertTrue(true);
});
});
$this->startServer(function () {
$this->connect("/app/INVALID-APP-KEY/room/INVALID-ROOM-ID", function () {
dump('connection #2');
$this->assertTrue(true);
});
});
dd('CONNECTION #1 IS OK. BUT SCRIPT FAILS CONNECTING #2 BECAUSE OF THE `await($promise)` ERROR: Value of type null is not callable in src/SimpleFiber.php IN react/async/src/SimpleFiber.php:74');
}
}
<?php
namespace Modules\Lobby\Tests\Unit\Sockets;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\Server\Router;
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
use Closure;
use Mockery;
use Mockery\MockInterface;
use Modules\Lobby\Interfaces\RoomSocketHandlerInterface;
use Modules\Lobby\Sockets\RoomSocketHandler;
use Orchestra\Testbench\TestCase;
use Ratchet\Client\WebSocket;
use Ratchet\Server\IoServer;
use Symfony\Component\Console\Output\BufferedOutput;
use Tests\CreatesApplication;
abstract class SocketTestCase extends TestCase
{
use CreatesApplication;
protected function startServer(Closure $closure = null): IoServer
{
/** @var WebSocketServerFactory $server */
$server = app(WebSocketServerFactory::class);
/** @var Router $route */
$route = WebSocketsRouter::getFacadeRoot();
$route->customRoutes(); // make custom routes available by calling ->getRoutes()
$ioServer = $server
->setHost(config('broadcasting.connections.pusher.options.host'))
->setPort(config('broadcasting.connections.pusher.options.port'))
->useRoutes($route->getRoutes())
->createServer();
if ($closure !== null) {
try {
$closure($ioServer);
} finally {
$ioServer->socket->close();
}
}
return $ioServer;
}
protected function connect(string $path, Closure $closure = null): void
{
$promise = \Ratchet\Client\connect($this->getFullConnectionString($path))
->then(
function (WebSocket $conn) use ($closure) {
try {
if ($closure !== null) {
$closure($conn);
}
} finally {
$conn->close();
}
}
);
/** @noinspection PhpUnhandledExceptionInspection */
\React\Async\await($promise);
}
protected function getFullConnectionString(string $path): string
{
return sprintf('%s://%s:%s/%s',
config('broadcasting.connections.pusher.options.scheme'),
config('broadcasting.connections.pusher.options.host'),
config('broadcasting.connections.pusher.options.port'),
$path
);
}
protected function getAppBasePath(string $appId): string
{
return sprintf('/app/%s',
$this->getLobbyAppConfig($appId)->key ?? ''
);
}
protected function getLobbyAppConfig(string $appId): ?App
{
/** @var AppProvider $provider */
$provider = app(config('websockets.app_provider'));
return $provider->findById($appId);
}
} Method
The error is triggered when called the next |
I managed to handle my problem. For the people who had the same issue, here's what I did to solve:
Here is the modified method: protected function connect(string $path, Closure $closure = null): void
{
$loop = Loop::get();
$promise = function () use ($path, $closure, $loop): void {
$request = connect($this->getFullConnectionString($path), [], [], $loop)
->then(
function (WebSocket $conn) use ($closure, $loop) {
try {
if ($closure !== null) {
$closure($conn);
}
} finally {
$conn->close();
$loop->stop();
}
},
function (Throwable $e) use ($loop) {
$loop->stop();
throw $e;
}
);
await($request);
};
async($promise)();
$loop->run();
} |
@mowses Thanks for your input on this 👍 Like I said above, the current error message is confusing and we want to give this a more meaningful content. @clue and I invested a few hours into a potential fix in the past, but we quickly ran into some overlaps with #65. It seems like we first need to file a new pull request in https://github.com/reactphp/event-loop in order to fix this here. We also have to define the expected behavior and write additional test cases. Stopping the loop like you described in your example above doesn't really fix the problem here. Additionally, you shouldn't use
We'll give an update once we filed the necessary pull requests and renamed this message to be more meaningful. |
I am getting the same error, now at assert() expression: $response = await(
$this->browser
->withResponseBuffer(1024 * 1024 * 32)
->withTimeout($timeout)
->request($method, $url, $headers, $body)
);
if (!$response) {
$this->tracerService->incScalar('http_error');
throw new Exception('Empty response');
} Thus this periodically throws Empty response because $response is NULL and when this happens I am getting:
reactphp/async is 4.3.0 |
Code: $response = await(async(static function () use ($timeout, $method, $url, $headers, $body) {
$connector = new Connector([
'tls' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$browser = new Browser($connector);
return $browser
->withResponseBuffer(1024 * 1024 * 32)
->withTimeout($timeout)
->request($method, $url, $headers, $body)
;
})()); Also produces
|
Reproduce:
How to fix it is known: wrap
$foo
intoAsync\async
. But the error sucks anyway. You guys gotta find a way to get it either work anyway, or throw a nice error telling us what is wrong and hinting what to do.The text was updated successfully, but these errors were encountered: