[Mono-dev] mono crash on exits when using COM.

Bill Holmes billholmes54 at gmail.com
Sat Jan 23 12:48:17 EST 2010


Tom,

I beleive that we had a problem with this before and I applied a fix.
http://anonsvn.mono-project.com/viewvc?view=revision&revision=121114

IIRC this code/fix should release all outstanding rcws before the
final collect of other mono objects, including ccws.

Can you investigate if this change (121114) has been broken, or needs enhanced?

-bill

On Fri, Jan 22, 2010 at 8:26 PM, tom hindle <tom_hindle at sil.org> wrote:
>
> I have added a check in mono_gc_run_finalize (void *obj, void *data)
> (gc.c):
>
> ---
>
> if (suspend_finalizers)
>                return;
>
> + if (mono_marshal_ccw_refcount(o) > 0)
> + {
> +  return;
> + }
>
> domain = o->vtable->domain;
>
> ----
>
> This seems to solve the problem. The ccw isn't freed, which means when
> the rcw releases its reference to the ccw, so it no longer segv's.
>
> Does this seem like an valid approach? I'm not sure If this means that
> finalize_domain_objects needs to make multiple passes at freeing the
> ccw's? I guess this change would also mean the badly written native COM
> objects would prevent ccw from being freed. Is this a problem?
>
> Thanks
> Tom
>
>
> On Fri, 2010-01-22 at 16:16 -0700, tom hindle wrote:
> > Hi all,
> >
> > I have been investigating some seemingly random crash on exit problems
> > that our application has been having.
> >
> > I have managed mostly reliably to reproduce the issue by following this
> > set of steps:
> >
> > 1. Create a managed object ManagedObj
> > 2. Create a COM object COMObj for which its rcw is likely to be Garbage
> > collected after ManagedObj and during mono shutdown.
> > 3. Make COMObj contain a ref to ManagedObj's ccw
> > 4. Set ManagedObj ref to null
> > 5. Call GC.Collect() to encourage GC.
> >
> > If Garbage Collection of COMObj's rcw happens after the Garbage
> > Collection of ManagedObj's ccw, then when COMObj calls Release on its
> > ref to ManagedObj's ccw a segv is produced.
> >
> > Normally it seems that ref counts for the wrappers are respected,
> > however this doesn't seem to be the case on program shutdown.
> >
> > Some pseudo code which reproduces the problem:
> >
> > public class TestComRelease
> > {
> > static COMObj cObj;
> >
> > [Test]
> > public void Test()
> > {
> >    ManagedObj mObj = new ManagedObj()
> >    cObj = new COMObj();
> >    cObj.SetManagedRef(mObj);
> >    mObj = null;
> >    GC.Collect();
> > }
> >
> > }
> >
> > I am attempting to find the cause of this in mono. Any pointers would be
> > grateful received.
> >
> > Thanks
> > Tom
> >
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list


More information about the Mono-devel-list mailing list