Ensure adapter is available during global destruction#106
Ensure adapter is available during global destruction#106mikkoi wants to merge 1 commit intopreaction:masterfrom
Conversation
Global Destruction The order in which objects are destroyed during the global destruction before the program exits is unpredictable. This means that any objects contained by your object may already have been destroyed. You should check that a contained object is defined before calling a method on it: https://perldoc.perl.org/perlobj#Global-Destruction Signed-off-by: Mikko Koivunalho <mikkoi@cpan.org>
|
(just a drive-by observation from another user) Your change would result in creation of a new adapter during global destruction. That generally won't work, as other objects that the adapter might want to access might be destroyed or partly destroyed. The only sensible behavior for a change to Log::Any itself would be to simply drop the log message as un-deliverable, but that doesn't necessarily solve anyone's problem. The real solution is to make sure all your destructors run before global destruction takes place, or make sure that you never access any object other than your own scalar fields during global destruction. If you are writing a module that logs things in the destructor, and you don't have control over whether the user of your module cleans up before program exit, the solution is |
|
Thank you, @nrdvana . I will try that. |
I am developing a testing tool which creates testing resources and then collects them when their reference count goes to zero. This means my code has a lot of activity in DESTRUCT phase. Often the DESTROY methods get executed only at the end of the program. So they go into global destruction. I was often receiving these errors:
... but not every time!
When I specifically reclaimed my objects by
undef'ing them or by letting them fall out of subroutine scope, the problem disappeared.Global Destruction
The order in which objects are destroyed during the global destruction before the program exits is unpredictable. This means that any objects contained by your object may already have been destroyed. You should check that a contained object is defined before calling a method on it:
-- https://perldoc.perl.org/perlobj#Global-Destruction