mixpanel-php icon indicating copy to clipboard operation
mixpanel-php copied to clipboard

Undefined offset: 1

Open markunsworth opened this issue 5 years ago • 0 comments

We're running a queue and for some jobs we send events to mixpanel (for example to know when an email was sent to a user). In order to do this and ensure that the events are sent at the end of the job we have added the following into a ServiceProvider:

       Queue::after(function (JobProcessed $event) {
            $mixpanel = App::get(Mixpanel::class);
            $mixpanel->flush();
        });

Sometimes, when the app calls flush we see the following error:

[2020-06-19 10:01:23] production.ERROR: Undefined offset: 1 {"exception":"[object] (ErrorException(code: 0): Undefined offset: 1 at /var/app/current/vendor/mixpanel/mixpanel-php/lib/ConsumerStrategies/SocketConsumer.php:286)
[stacktrace]
#0 /var/app/current/vendor/mixpanel/mixpanel-php/lib/ConsumerStrategies/SocketConsumer.php(286): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined offse...', '/var/app/curren...', 286, Array)
#1 /var/app/current/vendor/mixpanel/mixpanel-php/lib/ConsumerStrategies/SocketConsumer.php(252): ConsumerStrategies_SocketConsumer->handleResponse('')
#2 /var/app/current/vendor/mixpanel/mixpanel-php/lib/ConsumerStrategies/SocketConsumer.php(122): ConsumerStrategies_SocketConsumer->_write(Resource id #990, false)
#3 /var/app/current/vendor/mixpanel/mixpanel-php/lib/Producers/MixpanelBaseProducer.php(219): ConsumerStrategies_SocketConsumer->persist(Array)
#4 /var/app/current/vendor/mixpanel/mixpanel-php/lib/Producers/MixpanelBaseProducer.php(119): Producers_MixpanelBaseProducer->_persist(Array)
#5 /var/app/current/vendor/mixpanel/mixpanel-php/lib/Mixpanel.php(182): Producers_MixpanelBaseProducer->flush(50)
#6 /var/app/current/app/Providers/AppServiceProvider.php(114): Mixpanel->flush()
#7 /var/app/current/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(369): App\\Providers\\AppServiceProvider->App\\Providers\\{closure}(Object(Illuminate\\Queue\\Events\\JobProcessed))
#8 /var/app/current/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(218): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Queu...', Array)
#9 /var/app/current/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(526): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Queu...')
#10 /var/app/current/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(358): Illuminate\\Queue\\Worker->raiseAfterJobEvent('redis', Object(Illuminate\\Queue\\Jobs\\RedisJob))

It seems to be that in the handle_response method of the SocketConsumer the code expects a response that includes a space, but clearly that's not happening as $line_one_exploded doesn't have more than 1 value.

https://github.com/mixpanel/mixpanel-php/blob/1fde76865a6e8954ef132ecc90535c27790f663d/lib/ConsumerStrategies/SocketConsumer.php#L286

markunsworth avatar Jun 19 '20 10:06 markunsworth