You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in DefaultDynamicProxyMethodCheckerExtensions methods IsProxiable and ShouldBeProxiable are treating overridden Finalize methods as proxiable:
Both of these methods are used for lazy loading.
If during finalization object is not yet loaded, lazy proxy attempts to pull it from DB.
Since Finalize is called by GC at random times and random threads, it is unlikely that session will still be open during Finalize.
In most cases Finalize for lazy not yet loaded proxies throws an exception "Could not initialize proxy - no Session".
This bug occurs only if proxyable class has a base class, that is overriding Finalize, ie:
class Base { ~Base() { } }
class LazyChild : Base { } // this class will not be finalized
Currently in DefaultDynamicProxyMethodCheckerExtensions methods
IsProxiable
andShouldBeProxiable
are treating overriddenFinalize
methods as proxiable:Both of these methods are used for lazy loading.
If during finalization object is not yet loaded, lazy proxy attempts to pull it from DB.
Since Finalize is called by GC at random times and random threads, it is unlikely that session will still be open during Finalize.
In most cases Finalize for lazy not yet loaded proxies throws an exception "Could not initialize proxy - no Session".
This bug occurs only if proxyable class has a base class, that is overriding
Finalize
, ie:I've created a small demonstration project: https://github.com/ssharunas/nhibernate-finalization-bug-demonstration
IMHO Finalize should not be proxyable even in delivered classes.
The text was updated successfully, but these errors were encountered: