Skip to content
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

File are not removed for big payload size #48

Open
BBonnet22 opened this issue Jun 24, 2024 · 0 comments
Open

File are not removed for big payload size #48

BBonnet22 opened this issue Jun 24, 2024 · 0 comments

Comments

@BBonnet22
Copy link

When $maxTaskPayloadInBytes is greater than 100000 (by default), the \Spatie\Async\Runtime\ParentRuntime::encodeTask function creates a temporary file in the /tmp directory.

if (strlen($serializedTask) > $maxTaskPayloadInBytes) {
    // Write the serialized task to a temporary file and package it as a `FileTask`:
    $filename = tempnam(sys_get_temp_dir(), 'spatie_async_task_');
    file_put_contents($filename, $serializedTask);
    $file_task = new FileTask($filename);
    $serializedTask = base64_encode(serialize($file_task));
}

However, this function is called twice, resulting in two temporary files being created. At the end of the process, only one of these files is removed, leaving the other as a lingering temporary file.

The \VXM\Async\Runtime\ParentRuntime::createProcess method calls its parent method \Spatie\Async\Runtime\ParentRuntime::createProcess. Is there a specific reason for this? With this approach, everything looks to work fine

public static function createProcess($task, ?int $outputLength = null, ?string $binary = 'php', ?int $max_input_size = 100000): Runnable
    {
        if (! self::$isInitialised) {
            self::init();
        }

        if (! Pool::isSupported()) {
            return SynchronousProcess::create($task, self::getId());
        }

        $process = new Process([
            $binary,
            static::$childProcessScript,
            static::$autoloader,
            static::encodeTask($task),
            $outputLength,
            base_path(),
        ]);

        return ParallelProcess::create($process, self::getId());
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant