Skip to content

php core dump from ext-rdkafka #275

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

Closed
daydaygo opened this issue Sep 5, 2019 · 5 comments
Closed

php core dump from ext-rdkafka #275

daydaygo opened this issue Sep 5, 2019 · 5 comments
Assignees
Labels

Comments

@daydaygo
Copy link

daydaygo commented Sep 5, 2019

  • PHP version: 7.1.13
  • librdkafka version: 0.11.4
  • php-rdkafka version: 3.1.2
  • kafka version: 2.11-0.10.1.0

use gdb php /path/to/core.php, then use bt for backtrace

#0  ZEND_BIND_STATIC_SPEC_CV_CONST_HANDLER () at /opt/phpbrew/build/php-7.1.13/Zend/zend_vm_execute.h:40686
#1  0x000000000075139b in execute_ex (ex=<optimized out>) at /opt/phpbrew/build/php-7.1.13/Zend/zend_vm_execute.h:429
#2  0x00000000006fce51 in zend_call_function (fci=0x7f8d8d5974e0, fci_cache=0x7f8d8d597518)
    at /opt/phpbrew/build/php-7.1.13/Zend/zend_execute_API.c:855
#3  0x00007f8d913cf7b9 in zend_string_alloc (persistent=0, len=140734397967328)
    at /opt/phpbrew/php/php-7.1.13/include/php/Zend/zend_string.h:124
#4  zend_string_init (persistent=0, len=140734397967328, str=0x2ebcdb0 "")
    at /opt/phpbrew/php/php-7.1.13/include/php/Zend/zend_string.h:158
#5  kafka_conf_error_cb (rk=<optimized out>, err=<optimized out>, reason=0x2ebcdb0 "", opaque=0x7fff47cc6bc0)
    at /opt/phpbrew/build/php-7.1.13/ext/rdkafka/conf.c:154
#6  0x0000000002ebcdd8 in ?? ()
#7  0xffffffffffffffff in ?? ()
#8  0x0000000000000000 in ?? ()
@nick-zh
Copy link
Collaborator

nick-zh commented Sep 5, 2019

@daydaygo can you provide more information on what actually led to this core dump? thx in advance

@daydaygo
Copy link
Author

daydaygo commented Sep 5, 2019

  • gdb
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `/opt/phpbrew/php/php-7.1.13/bin/php /opt/pt-php-project/script/kafka-consumer/p'.
Program terminated with signal 11, Segmentation fault.
#0  ZEND_BIND_STATIC_SPEC_CV_CONST_HANDLER () at /opt/phpbrew/build/php-7.1.13/Zend/zend_vm_execute.h:40686
40686			if (Z_CONSTANT_P(value)) {
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.6-13.el7.x86_64 cyrus-sasl-lib-2.1.26-23.el7.x86_64 freetype-2.8-12.el7_6.1.x86_64 glibc-2.17-260.el7_6.4.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_6.x86_64 libcom_err-1.42.9-13.el7.x86_64 libcurl-7.29.0-51.el7.x86_64 libdb-5.3.21-24.el7.x86_64 libgcc-4.8.5-36.el7_6.1.x86_64 libgcrypt-1.5.3-14.el7.x86_64 libgpg-error-1.12-3.el7.x86_64 libidn-1.28-4.el7.x86_64 libjpeg-turbo-1.2.90-6.el7.x86_64 libmcrypt-2.5.8-13.el7.x86_64 libpng-1.5.13-7.el7_2.x86_64 libselinux-2.5-14.1.el7.x86_64 libssh2-1.4.3-12.el7_6.2.x86_64 libstdc++-4.8.5-36.el7_6.1.x86_64 libxml2-2.9.1-6.el7_2.3.x86_64 libxslt-1.1.28-5.el7.x86_64 ncurses-libs-5.9-14.20130511.el7_4.x86_64 nspr-4.19.0-1.el7_5.x86_64 nss-3.36.0-7.1.el7_6.x86_64 nss-softokn-freebl-3.36.0-5.el7_5.x86_64 nss-util-3.36.0-1.1.el7_6.x86_64 openldap-2.4.44-21.el7_6.x86_64 openssl-libs-1.0.2k-16.el7_6.1.x86_64 pcre-8.32-17.el7.x86_64 readline-6.2-10.el7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-18.el7.x86_64
(gdb) bt
#0  ZEND_BIND_STATIC_SPEC_CV_CONST_HANDLER () at /opt/phpbrew/build/php-7.1.13/Zend/zend_vm_execute.h:40686
#1  0x000000000075139b in execute_ex (ex=<optimized out>) at /opt/phpbrew/build/php-7.1.13/Zend/zend_vm_execute.h:429
#2  0x00000000006fce51 in zend_call_function (fci=0x7fcb4979e600, fci_cache=0x7fcb4979e638)
    at /opt/phpbrew/build/php-7.1.13/Zend/zend_execute_API.c:855
#3  0x00007fcb4d5cfa59 in rdkafka_call_function (retval=0x7ffc848a9180, params=0x7ffc848a9190, param_count=3,
    fci_cache=<optimized out>, fci=<optimized out>)
    at /opt/phpbrew/build/php-7.1.13/ext/rdkafka/php_rdkafka_priv.h:84
#4  kafka_conf_rebalance_cb (rk=<optimized out>, err=<optimized out>, partitions=<optimized out>,
    opaque=0x7fcb49776c88) at /opt/phpbrew/build/php-7.1.13/ext/rdkafka/conf.c:243
#5  0x00007fcb4d2be6ec in rd_kafka_poll_cb (rk=rk@entry=0x2584750, rkq=rkq@entry=0x2626f80,
    rko=rko@entry=0x7fcb3c00dd10, cb_type=cb_type@entry=RD_KAFKA_Q_CB_RETURN, opaque=opaque@entry=0x0)
    at rdkafka.c:3289
#6  0x00007fcb4d2bed24 in rd_kafka_consumer_close (rk=0x2584750) at rdkafka.c:2820
#7  0x00007fcb4d5d2ba2 in kafka_consumer_free (object=0x7fcb49776cc8)
    at /opt/phpbrew/build/php-7.1.13/ext/rdkafka/kafka_consumer.c:55
#8  0x0000000000746d81 in zend_objects_store_free_object_storage (
    objects=objects@entry=0x10239b8 <executor_globals+824>)
    at /opt/phpbrew/build/php-7.1.13/Zend/zend_objects_API.c:99
#9  0x00000000006fbe23 in shutdown_executor () at /opt/phpbrew/build/php-7.1.13/Zend/zend_execute_API.c:363
#10 0x000000000070c0f5 in zend_deactivate () at /opt/phpbrew/build/php-7.1.13/Zend/zend.c:1005
#11 0x00000000006abe31 in php_request_shutdown (dummy=dummy@entry=0x0)
    at /opt/phpbrew/build/php-7.1.13/main/main.c:1902
#12 0x00000000007a574b in do_cli (argc=2, argv=0x2395330) at /opt/phpbrew/build/php-7.1.13/sapi/cli/php_cli.c:1160
#13 0x000000000043adf0 in main (argc=2, argv=0x2395330) at /opt/phpbrew/build/php-7.1.13/sapi/cli/php_cli.c:1381
  • php code
private function getConsumer()
    {
        if ($this->consumer) {
            return $this->consumer;
        }

        $conf = new \RdKafka\Conf();
        //$conf->set("security.protocol", "SASL_SSL");
        $conf->set("sasl.mechanisms", "PLAIN");
        if (Config::get('kafka.username')) {
            $conf->set("sasl.username", Config::get('kafka.username'));
            $conf->set("sasl.password", Config::get('kafka.password'));
        }
        $conf->set("broker.version.fallback", "0.10.0.0");
        $conf->set("ssl.ca.location", dirname(__FILE__) . "./cert.pem");

        // Set a rebalance callback to log partition assignments (optional)
        $conf->setRebalanceCb(function (\RdKafka\KafkaConsumer $kafka, $err, array $partitions = null) {
            switch ($err) {
                case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS:
                    log_message("[KAFAK-CONSUMER] Assign:" . json_encode($partitions), LOG_INFO);
                    echo "Assign: ";
                    var_dump($partitions);
                    $kafka->assign($partitions);
                    break;

                case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS:
                    #echo "Revoke: ";
                    #var_dump($partitions);
                    log_message("[KAFAK-CONSUMER] Revoke:" . json_encode($partitions), LOG_INFO);
                    $kafka->assign(NULL);
                    break;

                default:
                    throw new \Exception($err);
            }
        });

        // Configure the group.id. All consumer with the same group.id will consume
        // different partitions.
        $conf->set('group.id', $this->options['group_id']);

        // Initial list of Kafka brokers
        $conf->set('metadata.broker.list', Config::get('kafka.addrs'));

        $topicConf = new \RdKafka\TopicConf();

        // Set where to start consuming messages when there is no initial offset in
        // offset store or the desired offset is out of range.
        // 'smallest': start from the beginning
        $topicConf->set('auto.offset.reset', 'smallest');

        //$topicConf->set("auto.commit.interval.ms", 1e3);
        //$topicConf->set("offset.store.sync.interval.ms", 60e3);
        //$topicConf->set("offset.store.path", dirname(__FILE__) . '/offsets/');

        // Set the configuration to use for subscribed/assigned topics
        $conf->setDefaultTopicConf($topicConf);

        $consumer = new \RdKafka\KafkaConsumer($conf);
        #$consumer->setLogLevel(LOG_DEBUG);

        $topics = $this->options['topics'];
        if (!is_array($topics)) {
            $topics = [ $topics ];
        }
        $consumer->subscribe($topics);

        $this->consumer = $consumer;

        return $this->consumer;
    }

    public function consume($handler)
    {
        $consumer = $this->getConsumer();

        if (!$consumer) {
            error_report("[KAFKA-CONSUMER] get consumer[{$this->options['group_id']}] error");
            return;
        }

        echo "Waiting for partition assignment... (make take some time when\n";
        echo "quickly re-joining the group after leaving it.)\n";

        $break_loop = FALSE;
        while (true) {
            $message = $consumer->consume($this->options['timeout']);
            switch ($message->err) {
                case RD_KAFKA_RESP_ERR_NO_ERROR:
                    $handler($message);
                    break;
                case RD_KAFKA_RESP_ERR__PARTITION_EOF:
                    echo "No more messages; will wait for more\n";
                    break
;
                case RD_KAFKA_RESP_ERR__TIMED_OUT:
                    echo "Timed out\n";
                    if ($this->options['quit_when_timeout']) {
                        $break_loop = TRUE;
                        break;
                    }
                    break;
                default:
                    throw new \Exception($message->errstr(), $message->err);
                    break;
            }
            if ($break_loop) {
                break;
            }
        }

        try {
            $consumer->commit();
        } catch (\Exception $e) {}
    }

@nick-zh
Copy link
Collaborator

nick-zh commented Sep 5, 2019

ok so i see in the trace that it has happening during the destruct of the consumer.
I think this is related to #196, there is unsafe behaviour that can happen if callbacks are getting
triggered during destruct. This was fixed recently and is now in master. You could try build master to see if you still have the problem or wait for the next release which should fix this.
The next release shouldn't be far along.

@daydaygo
Copy link
Author

daydaygo commented Sep 5, 2019

@nick-zh i got core.php file and use gdb for the info, how to get more info to debug this problem? i can't get when it happen. but i guess when deploy happened and the application restart, the rakafka consumer may produce the core.php file

@nick-zh
Copy link
Collaborator

nick-zh commented Sep 5, 2019

@daydaygo no it's ok, i think i know what the problem is, disregard my previous message, we fixed this for the low level consumer, i see that we still have this behaviour in the high level consumer, i will try to provide a fix very soon.

@nick-zh nick-zh self-assigned this Sep 5, 2019
@nick-zh nick-zh added bug and removed wait-info labels Sep 5, 2019
@nick-zh nick-zh closed this as completed Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants