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

Invalid request phase transition from ServerProcessing to Connect #52

Open
kelunik opened this issue Jul 24, 2024 · 0 comments
Open

Invalid request phase transition from ServerProcessing to Connect #52

kelunik opened this issue Jul 24, 2024 · 0 comments
Labels

Comments

@kelunik
Copy link
Member

kelunik commented Jul 24, 2024

An invalid request phase transition happens if the connection isn't properly established, here because dum-increment-protocol is passed instead of dumb-increment-protocol.

<?php

require \dirname(__DIR__) . '/vendor/autoload.php';

use Amp\Websocket\Client\WebsocketHandshake;
use function Amp\Websocket\Client\connect;

// Connects to the websocket endpoint at libwebsockets.org which sends a message every 50ms.
$handshake = (new WebsocketHandshake('wss://libwebsockets.org'))
    ->withHeader('Sec-WebSocket-Protocol', 'dum-increment-protocol');

$connection = connect($handshake);

while ($message = $connection->receive()) {
    $payload = $message->buffer();

    \printf("Received: %s\n", $payload);

    if ($payload === '100') {
        $connection->close();
        break;
    }
}
➜ php examples/libwebsockets.org.php

Fatal error: Uncaught Error: Invalid request phase transition from ServerProcessing to Connect in /Users/kelunik/PHP/amphp/websocket-client/vendor/amphp/http-client/src/Internal/EventInvoker.php on line 85

Error: Invalid request phase transition from ServerProcessing to Connect in /Users/kelunik/PHP/amphp/websocket-client/vendor/amphp/http-client/src/Internal/EventInvoker.php on line 85

Call Stack:
    0.0406    5097232   1. {fiber:1053903C0}() /Users/kelunik/PHP/amphp/websocket-client/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php:498
    0.0406    5117712   2. Revolt\EventLoop\Driver\StreamSelectDriver->Revolt\EventLoop\Internal\{closure:/Users/kelunik/PHP/amphp/websocket-client/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php:560-622}() /Users/kelunik/PHP/amphp/websocket-client/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php:498
    0.2997    6165592   3. Revolt\EventLoop\Driver\StreamSelectDriver->invokeMicrotasks() /Users/kelunik/PHP/amphp/websocket-client/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php:616
    0.2999    6171544   4. Amp\{closure:/Users/kelunik/PHP/amphp/websocket-client/vendor/amphp/amp/src/functions.php:23-37}() /Users/kelunik/PHP/amphp/websocket-client/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php:425
    0.2999    6171704   5. Amp\Http\Client\Connection\DefaultConnectionFactory->create() /Users/kelunik/PHP/amphp/websocket-client/vendor/amphp/amp/src/functions.php:33
    0.3000    6171704   6. Amp\Http\Client\Internal\EventInvoker->connectStart() /Users/kelunik/PHP/amphp/websocket-client/vendor/amphp/http-client/src/Connection/DefaultConnectionFactory.php:33
@kelunik kelunik added the bug label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant