Skip to content

Coroutine safety: PHP Fatal error: Cannot redeclare class #404

@wilaak

Description

@wilaak

Version 3.1.0

Hi, I'm running into issues when using latte in Swoole coroutines with runtime hooks enabled.

Trace

PHP Fatal error:  Cannot redeclare class Template_389fc8e4d9 (previously declared in [REDACTED_PATH]/.latte-cache/template-index.latte--389fc8e4d9.php:10) in [REDACTED_PATH]/.latte-cache/template-index.latte--389fc8e4d9.php on line 10
[REDACTED_TIMESTAMP] ERROR   php_swoole_server_rshutdown() (ERRNO 503): Fatal error: Cannot redeclare class Template_389fc8e4d9 (previously declared in [REDACTED_PATH]/.latte-cache/template-index.latte--389fc8e4d9.php:10) in [REDACTED_PATH]/.latte-cache/template-index.latte--389fc8e4d9.php on line 10

Steps to reproduce

The issue seems to occur when under high load and seemingly at random. Maybe an issue of using eval() without proper isolation, two coroutines may try to load or compile the same template at the same time. (I'm only guessing here)

// This will make built-in functions coroutine friendly
\Swoole\Runtime::enableCoroutine();

Then just use the templating engine as normal

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