Bug #85245
closedFileWriter instance throws error if used in serialized/unserialized objects
100%
Description
How to reproduce:¶
- Current master
- Add the following config to AdditionalConfiguration:
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [
\TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
'logFile' => 'typo3temp/var/logs/debug.log',
],
],
];
- Open the scheduler
- Create a new task, add a frequency, try to save
--> fwrite expects parameter to be resource, null given
Background:¶
- The LogManager instanciates logger instances per class name and GeneralUtility::makeInstance injects these via loggerAwareInterface (or they are fetched via the LogManager directly).
- When constructed, the FileWriter will call "openLogFile" and store the created file handle (fopen...) in a static member variable to share between instances
- The __destruct method closes that file handle
- On serialization / sleep / wake-up static vars aren't resetted, if there was a destruct call before wake-up happens, the file handle may be unset even though it is still needed
- If multiple instances use the same file handle, the handle should only be closed if the last of the instances is destructed (see test in patch)
- The bug appears only now, because with the logging in extbase signalSlotDispatcher the core first uses a logger in a context a) frequently used and b) serialized
- The fix only fixes the FileWriter part, a second issue is the general handling of serialized LoggerAware objects, as these - independent of the configured writer - serialize their configuration, too, which might change in between serialization and unserialization