swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.05k stars 390 forks source link

Event data cannot be an array anymore (changed from mixed to ?string) #511

Closed rdrenth closed 2 years ago

rdrenth commented 2 years ago

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)

php -v

PHP 7.4.26 (cli) (built: Nov 18 2021 16:22:49) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.26, Copyright (c), by Zend Technologies

php --ri swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.8.2
Built => Nov 23 2021 19:15:21
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1l  24 Aug 2021
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. Please provide your Laravel/Lumen version.

php artisan --version

Laravel Framework 8.68.1
  1. Which release version of this package are you using?

v2.10.0

  1. What did you do? If possible, provide a recipe for reproducing the error.

Emit an event where $input->getEventName() is a string, and where $input->getEventPayload() is an array.

$this->websocket->emit($input->getEventName(), $input->getEventPayload());
  1. What did you expect to see?

An succesful emitted event.

  1. What did you see instead?

An exception was thrown.

Argument 7 passed to SwooleTW\Http\Websocket\Pusher::__construct() must be of the type string or null, array given, called in /app/pusher/vendor/swooletw/laravel-swoole/src/Websocket/Pusher.php on line 96 {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Argument 7 passed to SwooleTW\\Http\\Websocket\\Pusher::__construct() must be of the type string or null, array given, called in /app/pusher/vendor/swooletw/laravel-swoole/src/Websocket/Pusher.php on line 96 at /app/pusher/vendor/swooletw/laravel-swoole/src/Websocket/Pusher.php:64)
[stacktrace]
#0 /app/pusher/vendor/swooletw/laravel-swoole/src/Websocket/Pusher.php(96): SwooleTW\\Http\\Websocket\\Pusher->__construct(1, 0, Array, true, true, 'test123', Array, Object(Swoole\\WebSocket\\Server))
#1 /app/pusher/vendor/swooletw/laravel-swoole/src/Concerns/InteractsWithWebsocket.php(215): SwooleTW\\Http\\Websocket\\Pusher::make(Array, Object(Swoole\\WebSocket\\Server))
#2 /app/pusher/vendor/swooletw/laravel-swoole/src/Server/Manager.php(281): SwooleTW\\Http\\Server\\Manager->pushMessage(Object(Swoole\\WebSocket\\Server), Array)
#3 [internal function]: SwooleTW\\Http\\Server\\Manager->onTask(Object(Swoole\\WebSocket\\Server), 0, 0, Array)
#4 /app/pusher/vendor/swooletw/laravel-swoole/src/Server/Manager.php(99): Swoole\\Server->start()
#5 /app/pusher/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(137): SwooleTW\\Http\\Server\\Manager->run()
#6 /app/pusher/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(98): SwooleTW\\Http\\Commands\\HttpServerCommand->start()
#7 /app/pusher/vendor/swooletw/laravel-swoole/src/Commands/HttpServerCommand.php(74): SwooleTW\\Http\\Commands\\HttpServerCommand->runAction()
#8 /app/pusher/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): SwooleTW\\Http\\Commands\\HttpServerCommand->handle()
#9 /app/pusher/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 /app/pusher/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#11 /app/pusher/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#12 /app/pusher/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#13 /app/pusher/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#14 /app/pusher/vendor/symfony/console/Command/Command.php(299): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#15 /app/pusher/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#16 /app/pusher/vendor/symfony/console/Application.php(978): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /app/pusher/vendor/symfony/console/Application.php(295): Symfony\\Component\\Console\\Application->doRunCommand(Object(SwooleTW\\Http\\Commands\\HttpServerCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /app/pusher/vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 /app/pusher/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 /app/pusher/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 /app/pusher/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 {main}

This issue and related PR caused this to break since version 2.10.0. The constructor $message property was type-hinted as ?string, while it was a mixed type and also documented as a mixed type on the wiki (function emit).

See constructor of class SwooleTW\Http\Websocket\Pusher:

/**
 * Push constructor.
 *
 * @param int $opcode
 * @param int $sender
 * @param array $descriptors
 * @param bool $broadcast
 * @param bool $assigned
 * @param string $event
 * @param mixed|null $message
 * @param \Swoole\Websocket\Server
 */
protected function __construct(
    int $opcode,
    int $sender,
    array $descriptors,
    bool $broadcast,
    bool $assigned,
    string $event,
    ?string $message,
    $server
)

Can you please correct this breaking change, thank you.

Arkanius commented 2 years ago

Hi there, thanks to reporting this. Indeed it looks like a mistake by me, sorry about that.

Trying to think about this without need to release a major version just to update it

HadiAghandeh commented 2 years ago

I am having the same issue. laravel 8.77.1 php 8.1

I had to downgrade to v2.9.0

HadiAghandeh commented 2 years ago

@Arkanius Is it going to be fixed?

rdrenth commented 2 years ago

Will this be addressed at some point? Thanks.

Arkanius commented 2 years ago

Thanks guys,

Rollback applied as https://github.com/swooletw/laravel-swoole/releases/tag/v2.12.1

@hadiaec20h @rdrenth