Crash when using coroutines

Crash when using coroutines

Postby X512 » Sat Nov 16, 2019 11:52 am

This is blackbox-1.7.3-a1.1115.

Steps to reproduce:
1. Compile 2 modules below.
2. Execute "A.Open". New empty window will open.
3. Execute "A.Run". 16 moving black circles will be added to window. Each black circle is processed in separate coroutine.
4. Unload module A.
5. Repeat 2-4 several times.
6. 3 error patterns appear. First is silent process termination. Second is freezing forever with 100% main thread load. Third is Endless trap window attached.

This bug is probably caused by deleting Kernel.Coroutine object by garbage collector causing dangling pointers Coroutine.prev/next in coroutine list anchored in Kernel.currentCoroutine. Crash is probably caused by accessing dangling pointer c.next in Kernel.MarkReferencedCoroutines.

Bug can be fixed by adding finalizer to Kernel.Coroutine:

Code: Select all
   PROCEDURE (c: Coroutine) FINALIZE-;
   BEGIN
      IF c.next # NIL THEN RemoveCoroutine(c) END;
   END FINALIZE;


After this modification, finalizer in module Coroutines can be removed.

Test module
Code: Select all
StdCoder.Decode ..,, ..GV,...3Qw7uP5PRPPNR9Rbf9b8R79FTvMf1GomCrlAy2xhX,Cb2x
 hXhC6FU1xhiZiVBhihgmRiioedhgrZcZRiXFfaqmSrtuGfa4700zdGrr8rmCLLCJuyKtYcZRiX
 7.2.s,spj.,6.5Qw7uP51QCPuP7PNN9F9vQAy1xB.gdj,UBxhYhAbf9P0G2sIdvPZntgcghghZ
 cZRC8T0E.kGS,H.vs32.,U08J99SdfJHPNjvQCJuGKfaqmY6MwdONl1QCh0708T,U..w.wsK.,
 sUGpmWbBxhYhAbndMHT9NY6Mw.sQq2Y6cwB.0.XC3w,AtIE.0.4Eh5.86.QC18RdfQHfMf9R9v
 Q7ONb17.,.X,,6.I16.M.,.JFyuv.U.2m,.Zuzzzz0,0EwHzzzz.8Mtr.2.872.e,2.A.c8.2U
 wK.6yzzzzLdyzzBUuzzzzz.Ivyzzzv.6.tzzzzzS..K.Ipyzzzf.EyV5.Fzzzzz8.YTs,E2vzz
 zz.OzzzzzZjyzzz5U.E.evC9U0Kb0cUXDF9fR5uP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M6Rm0CZZ
 dQO5MNC5uajtR.M0aYCtEWWd3kd66,QF6FiXBU3dH668ZpVv.qU76I,YD,G2MF0W17P,QN,QM,
 gQ,g8i1M0O366Cau66CYjVjNRMOuaZNA.82S2M1M0SZ6NGm20WXtP6HsQGbUs6,A6uI.bI.nYU
 2k2VBU7UX76e1..Uv66C4.UUcC...uWiNNW5iXBU7UHVmdRUZtQuWG3kZ3kh3kj3kq3kZ3k,3k
 X7RaajdPWG.d944M8.a.O5K4cIMPcR68C4yad2EU7MF6Fi1.66CYg,sC,2qU13kA3kDtI,QF,A
 6C2.U33EU,d9,Q1,Q1,g.18URlb2i.Grg,3.8Zp,.5Gqkkk40cW2k13kjVjNRUiNNC5CYg,uap
 3kk3kv66i28biVgd9,wEyag7P,QNC4i1....UW2kB2k0CyIV1xhiZimxhgZhZJinpZHlVGLtmK
 WKqtCK.4Te..c95uPR9R.7ONbvM,kVkk.Um,..Unp3.6F6.ZD,6.636.M00U.2..AU0CyIhA8p
 umqm8rtumdcIf9PY62Ulb8.CLL8pumqmY62UmT.0U.kJl16.53,6.C6.QiiQ8CJuaLqKKWKqt2
 Ul1.RVtZBE.8z1U..2,0Eh2.0.32.oZ,ZC.G20U2U...G00k.0.0.0mFf32Uwpr,sbTX,U,U.2
 .8Mtr.2..c4E.k.Ue6T6.2UEC.6..mEw71s1D6Kmk1Sn.8ssHorMPU1xB..8V.E..U6U..N6.2
 Uohfn76Dtc0MyfU.az86x,9O0OJWd..sF,...
 --- end of encoding ---


Objects views module
Code: Select all
StdCoder.Decode ..,, ..bN,...3Qw7uP5PRPPNR9Rbf9b8R79FTvMf1GomCrlAy2xhX,Cb2x
 hXhC6FU1xhiZiVBhihgmRiioedhgrZcZRiXFfaqmSrtuGfa4700zdGrr8rmCLLCJuyKtYcZRiX
 7.2.s,6vf.0k,5TWyql.bnayKmKKqGomC5XzET1.PuP.MHT9N9ntumaU2,CJuyKtQC98P9PP7O
 NbXmb.2.IbJk2ENK,,6.,U08J99SdfJ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4Y.K5EN0MO0MM0MJ.Z1b1V1H
 1Q5k2kWEWQ5k2YD0sq.p,V0T1ICABQCRFdktAh.KD28gABHEY6.H.P1DHL2BTHtoc.Ch.aCd8U
 T9Uj8UH9URHEI5v,dGd0se0sW0sR06A,gB.h9U9Hto6.T1..I8.k2g6N8UbmWg,Hk2g6R0..,F
 YAAYAN1V0T1P0Q5k4Ec0Mdw7EW.9GEo799UjHJEIA3p,h09nvQ5k2o810,Fv.h0.EVkXEbg,A,
 RmWw8F,H,,7UH0HHuo8gA23.P.HEdg6dmeEbEvQb.09070R0Q5k4A,V8U..g6,FWgg.4i.yBbn
 oYCJlR06I6w6k4k2o8H1QCRFWgA.H1F7UR8UEIA3H7U.907GEY6..r,g,98U.3GL0s40s40M,8
 G.9I.vW2NN..0G.DZo7N,wE,QP,AN,wQ,YD3kk3kZdP,g6,Q1,g..Es.....V8U19Ub9Udnmo8
 .37UPE,5TekVyKrGLtyKqmqm8rtumdsEdfQN9F9vQ59.XDJ..oZ1xhiZCU2hgnRg.sEMM.Et..
 .ktu0.Y62Umb.2.Y02.A,,E.0..4E,5TeK4ZORNPNZvQRtIIepZBG20ksH3.bf9ZORNPNG20Et
 D.,E.ses,sc6.,k,,UnpZHldGrwmqmGomCb.AS.c9Ajg,0EtT.,E..W.,cK0.,U00.umUG5.70
 ,E0E...7,,M.,.,.,tcp00Eyuv.wnj7.1.1.,6.Ikmj,6..EBU.U,.J,2.0E65.2..N6yY,YxJ
 B939PTL,5TWy4P1bnVy4..ZE.6..E2E.UA2U.6.dPLbHESmF3kwL,,AzJEu1Ko2oe2H.rl,...
  --- end of encoding ---
Attachments
CoroutinesError.PNG
Trap window
X512
 
Posts: 43
Joined: Sat Feb 07, 2015 2:51 pm

Re: Crash when using coroutines

Postby Josef Templ » Sun Nov 17, 2019 8:31 pm

thanks for the bug report and the careful analysis.

There was a similar issue reported by Robert some time ago but we were not able to reproduce it and thus have given up on it.
It is possible, and even likely, that the issues are related.

The proposed bug fix is simple and looks appealing.
However, I don't fully understand what causes the difference in the behavior.
Can you give a plausible explanation why the bug fix works?

- Josef
Josef Templ
 
Posts: 244
Joined: Tue Sep 17, 2013 6:50 am

Re: Crash when using coroutines

Postby X512 » Mon Nov 18, 2019 4:15 pm

Kernel.Coroutine.prev/next pointers are untagged and not traced by garbage collector, so object pointed by this pointers can be deleted by garbage collector making dangling pointers. This dangling pointers are causing crash when traversing coroutine stacks in mark phase (Kernel.MarkReferencedCoroutines). Adding finalizer to Kernel.Coroutine ensures that Coroutine will be removed from list before being deleted.

I also found another bug causing crash on exit. After Kernel.EndCoroutines have been called, finalizer of main coroutine delete main thread stack causing memory access error.

This can be fixed by set main coroutine fiber handle to 0:
Code: Select all
   PROCEDURE EndCoroutines*;
      VAR res: INTEGER;
   BEGIN
      IF mainCoroutineRefcnt > 0 THEN
         DEC(mainCoroutineRefcnt);
         IF mainCoroutineRefcnt = 0 THEN
            mainCoroutine.fiber := 0; (* <-- added *)
            currentCoroutine := NIL; mainCoroutine := NIL;
            res := WinApi.ConvertFiberToThread()
         END
      END
   END EndCoroutines;
X512
 
Posts: 43
Joined: Sat Feb 07, 2015 2:51 pm

Re: Crash when using coroutines

Postby Josef Templ » Mon Nov 18, 2019 8:58 pm

Thanks, this makes it a lot clearer, however,
coroutines always come as pairs (Coroutines.Coroutine, Kernel.Coroutine) where Coroutines.Coroutine.impl
points to the lower-level Kernel.Coroutine object.
There should never be a dangling pointer because .impl is a tracked pointer.
Whenever a Coroutines.Coroutine becomes unreachable, its finalizer removes the associated Kernel.Coroutine object.
This link must be broken somewhere.

- Josef
Josef Templ
 
Posts: 244
Joined: Tue Sep 17, 2013 6:50 am

Re: Crash when using coroutines

Postby Josef Templ » Mon Nov 18, 2019 10:41 pm

I think I do understand now what is going on.

In Kernel.ExecFinalizer there is an extra check for finalizing objects of unloaded modules.

Code: Select all
IF (fin # NIL) & (f.blk.tag.mod.refcnt >= 0) THEN fin(S.VAL(ANYPTR, S.ADR(f.blk.last))) END;

If your test module A is unloaded, then the finalizer of the coroutine object is not executed.
This creates an orphaned Kernel.Coroutine object that gets garbage collected later but not unlinked,
as you described.

So, moving the finalizer into Kernel is a perfect fix for the bug, I think.

- Josef
Josef Templ
 
Posts: 244
Joined: Tue Sep 17, 2013 6:50 am

Re: Crash when using coroutines

Postby Josef Templ » Sat Nov 23, 2019 6:51 pm

@X512
Please have a look at http://blackboxframework.org/unstable/issue-%23197/blackbox-1.7.3-a1.1120.zip for the fix as you proposed.

The list of changes is in https://redmine.blackboxframework.org/projects/blackbox/repository/revisions/93acb1d2fc68882b5f8382a78b3bbad0a8f88ab6/diff/.

Thanks again for your analysis and bug fix proposal

- Josef
Josef Templ
 
Posts: 244
Joined: Tue Sep 17, 2013 6:50 am

Re: Crash when using coroutines

Postby luowy » Sun Nov 24, 2019 4:29 pm

unfortunately, it traps out many window when close the opened View ;

the step of test:
1, click TestA.Open
2, click TestA.Run ;
3, close the view (dont click TestA.Clear!)
the view can't close normally when action running;
Attachments
Test.zip
(10.72 KiB) Downloaded 57 times
luowy
 
Posts: 51
Joined: Thu Dec 17, 2015 1:32 pm

Re: Crash when using coroutines

Postby X512 » Sun Nov 24, 2019 4:56 pm

X512
 
Posts: 43
Joined: Sat Feb 07, 2015 2:51 pm

Re: Crash when using coroutines

Postby X512 » Sun Nov 24, 2019 5:03 pm

luowy wrote:unfortunately, it traps out many window when close the opened View ;

If trap contents is like this
Code: Select all
NIL dereference (read)

 Windows.RootContext.GetSize   [000007F2H]
   .c   Windows.RootContext   [02A85B50H]
   .h   INTEGER   2143944424
   .w   INTEGER   19334948

than this is intended behavior. Each coroutine crash because getting size of closed view crashes. Each coroutine has separate exception handling.
X512
 
Posts: 43
Joined: Sat Feb 07, 2015 2:51 pm

Re: Crash when using coroutines

Postby luowy » Tue Nov 26, 2019 7:26 am

X512 wrote: this is intended behavior. Each coroutine crash because getting size of closed view crashes. Each coroutine has separate exception handling.
yes ,it is! thanks your reply;it's a pity the maximum number of coroutines is limited to about 150; I know the stack size is limited to 2M,why can golang run so many coroutines?(I know very little about golang)
luowy
 
Posts: 51
Joined: Thu Dec 17, 2015 1:32 pm

Next

Return to Bug

Who is online

Users browsing this forum: No registered users and 0 guests