Skip to content

KafkaErrorException: The server experienced an unexpected error when processing the request #105

@rodrifarias

Description

@rodrifarias
  • What problem did you encounter?
    When using the longlang/phpkafka library, we intermittently encounter the following error:
    longlang\phpkafka\Exception\KafkaErrorException: [-1] The server experienced an unexpected error when processing the request.

This happens sporadically during regular Kafka consumption, causing interruptions in our consumer application.

The problem only occurs in version 2.3.0 of kafka

  • Is the Kafka environment self-built or cloud service?
    Self-built.

  • Please execute the following command to get environment information.

php -v & php --ri swoole & composer info | grep longlang/phpkafka

PHP 8.3.14 (cli) (built: Nov 21 2024 08:44:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.14, Copyright (c), by Zend Technologies

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 6.0.2
Built => Apr 25 2025 10:17:40
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 3.1.8 11 Feb 2025
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
curl-version => 8.12.1
c-ares => 1.27.0
zlib => 1.3.1
brotli => E16781312/D16781312
mutex_timedlock => enabled
pthread_barrier => enabled
coroutine_pgsql => enabled
coroutine_odbc => enabled
coroutine_sqlite => enabled

Directive => Local Value => Master Value
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
longlang/phpkafka                              1.2.5   A kafka client. Support php-fpm and Swoole.


  • Provide the smallest reproducible code:
<?php

require_once __DIR__ . '/vendor/autoload.php';

use longlang\phpkafka\Consumer\Consumer;
use longlang\phpkafka\Consumer\ConsumerConfig;

$config = new ConsumerConfig();
$config->setBroker('localhost:9092');
$config->setTopic('topic_name');
$config->setGroupId('grupo_id');
$config->setGroupInstanceId('group_instance_id');

$consumer = new Consumer($config);

while (true) {
    $message = $consumer->consume();
    if ($message) {
        // Processing message logic
    }
}

The solution is to allow sending group_instance_id as null in the GroupManager.php class on lines 99 and 114

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions