componere
componere copied to clipboard
Segfault on teardown
This is more a note, rather then a bug report.
-> We have a class instance (lets call it Patcher class) holding reference to all definitions (patched classes definitions) -> Class instance is created when we boot Symfony kernel, we want to keep our patched classes to be patched as long as PHP process is ongoing (Request->Response cycle, or CLI command is being executed). -> When we execute CLI command, we get segfault
We hypothesised that issue is in Componere, that is, all patched instances are garbage collected prior to definitions which causes segfault.
Our solution was to add __destruct method to class holding reference to definitions and to release them as soon as we do not need them anymore.
class Patcher {
private array $definitions = [];
// public function addDefinition() { ... }
public __destruct() { // we just added this method.
$this->definitions = [];
}
}
By simply adding destructor, we don't have segfault issue anymore.
I am not sure if I can write a proper test which could replicate an issue, but it seams that issue is in when patched instances are being garbage collected before definitions are garbage collected (at least we think so).