ydb-platform / ydb-platform/ydb-php-sdk

bug: Использование любой имплементации LoggerInterface приводит к ошибке, Serialization of 'Closure' is not allowed

Open
#143 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
39
Forks
19
Avg merge
1d 15h
Merged PRs (30d)
2

Description

Bug Report

YDB PHP SDK version:

v1.15.0

Environment

Ubuntu 24.04, Docker Desktop 4.30.0, PHP 8.2 laravel/framework v10.47.0

Current behavior:

При попытке использовать LoggerInterface(Symfony\Component\HttpKernel\Log\Logger - symfony/http-kernel:v6.4.5)
Получаем ошибку
Serialization of 'Closure' is not allowed {"exception":"[object] (Exception(code: 0): Serialization of 'Closure' is not allowed at /app/vendor/ydb-platform/ydb-php-sdk/src/Iam.php:354)

Путём небольшого анализа кода было выясненно, что это происходит при попытке сериализации $config во время формирования имени для временного файла

Expected behavior:

Отсутствие ошибки

Steps to reproduce:

Создать экземпляр YDB, с указанием любых настроек и передачей LoggerInterface в качестве второго параметра
После чего вызвать

Related code:

/**
     * @return string
     */
    protected function getTokenTempFile()
    {
        if (empty($this->token_temp_file))
        {
            $temp_dir = $this->config('temp_dir');

            if (!is_dir($temp_dir))
            {
                mkdir($temp_dir, 0600, true);
            }

            $this->token_temp_file = $temp_dir . '/ydb-iam-' . md5(serialize($this->config)) . '.json';
        }

        return $this->token_temp_file;

Other information:

проверено так же с использованием
Illuminate\Log\LogManager - laravel/framework v10.47.0 и вызвает аналогичный результат, мне кажется что проблему можно было бы решить, изменить способ формирования временного файла, или при помощи сужения полей md5(serialize($this->config))
Вот один из примеров, которым можно было бы исправить ошибку

    protected function getTokenTempFile()
    {
        if (empty($this->token_temp_file))
        {
            $temp_dir = $this->config('temp_dir');

            if (!is_dir($temp_dir))
            {
                mkdir($temp_dir, 0600, true);
            }
            
            $this->token_temp_file = $temp_dir . '/ydb-iam-' . md5(serialize(array_filter($this->config, static fn ($key) => $key !== 'credentials', ARRAY_FILTER_USE_KEY))) . '.json';
        }

        return $this->token_temp_file;
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Iam.php at getTokenTempFile() and reproduce the failure with a Symfony or Laravel LoggerInterface implementation in the stated PHP environment. Check how config is used to derive the temporary token filename; done means logger-backed configurations no longer trigger closure serialization while the temporary file naming remains usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php, symfony
Domain
authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.