Jump to content
RDPasqua

heavy bug 10.2 10.3 RIO passing parameter pointers in anonymous methods

Recommended Posts

hello,

 

I'm using a wrapper of the Intel TBB memory manager, working perfectly, then I have discovered a grave bug that don't permits to replace the default MM in Tokio, RIO if you use new compiler features.

 

This happens when you use anonymous functions with generics,

for example you call inside this function another function passing a PPType

the function calls New() on the result then using fillchar sizeof ^PType

ok, the pointer is not passing between the calling functions, generating Violation Access

 

CL1.jpg

Share this post


Link to post

From looking at the callstack I am pretty sure there is a defect it's in your code namely in TIocpCrossSocket._NewAccept or the code that calls this method in case of AListen being nil.

Share this post


Link to post

Are you able to reproduce this bug in a somewhat simpler example?

Share this post


Link to post

It’s a nice library called delphi-cross-socket

 

why default mm is tolerant to these errors? 

 

Later I post both TBB wrapper and the lib, tjanks

Share this post


Link to post

Try removing the inline from function TIocpCrossSocket._NewIoData: PPerIoData; - possible that it trips over something there - apart from that I don't see how this could be related to anonymous methods. The variable assigned to is a local variable of a regular method and there are no anonymous methods in procedure TIocpCrossSocket._NewAccept(AListen: ICrossListen); that could change the location of that variable to somewhere else than the stack.

 

Possible that the TBB code is sensitive to some garbage value in a volatile register that it does not properly check for.

Edited by Stefan Glienke

Share this post


Link to post

hi,

if you have time

https://github.com/winddriver/Delphi-Cross-Socket a great library to do async scalable server (really well done the windows counterpart), check for example the websocketdemo

 

extract the attached file

there are two libs and relative units, I did custom DLL from Intel TBB and Intel IPP projects because I'm near to release on github a Isapi deflate filter for IIS 10 (5x faster vs system)

Put RDPMM64 as first unit to replace the MM and debug websocketdemo.

Feel free to use internally those libs for your purposes, but please don't redistribute, because in the actual form they violate 2 licenses (microsoft requires to link to visualC redistributable setup (instead I did smart linking inside one small dll), same thing Intel requires to redistribute whole libraries IPP, both tens of megabytes....) anyway

with those patches (MM, fillchar, move, pos) some server benchmark shows 3x improvement in quad core server (multithreaded distributed load)

 

ok, let me know, I'm here if you need, thanks

IntelIPP_Delphi.zip

Share this post


Link to post

(I forgot, the patches works perfectly with big size Delphi projects, I need figure out the troubles with DelphiCrossSocket...)

Share this post


Link to post

I'm sorry to insist but libraries are not simple. And neither is the need to install one to reproduce a bug, that is supposed to be rooted in the IDE.

Share this post


Link to post

There clearly is a race condition somewhere in the SeaMM.dll - either it works, or it raises AVs until it stackoverflows or it gets stuck inside a loop (keep clicking Start/Stop if it does not raise AV/SO) with these instructions:

 

00007FF9B59FB520 664103D0         add dx,r8w
00007FF9B59FB524 488BD9           mov rbx,rcx
00007FF9B59FB527 66895774         mov [rdi+$74],dx
00007FF9B59FB52B 488B01           mov rax,[rcx]
00007FF9B59FB52E 488BC8           mov rcx,rax
00007FF9B59FB531 4883C801         or rax,$01
00007FF9B59FB535 4883F801         cmp rax,$01
00007FF9B59FB539 75E5             jnz $00007ff9b59fb520

Anyway as you seem to be the author/modifier of that code you should be able to debug that yourself.

As soon as I put a breakpoint I could not get the AV - which confirms my guess about the race condition.

Edited by Stefan Glienke

Share this post


Link to post

So the problem is the Intel TBB? Maybe I forgot a multithread flag /MD /MT etc. compiling it, hmmm... I try 😕

 

thanks for your kind help 

Edited by RDPasqua

Share this post


Link to post

ok just tried unmodified Intel compiled DLL https://github.com/01org/tbb/releases (you can check bin folder tbbmalloc.dll)

the problem persist, so in my opinion cannot be a problem of this library, but somewhere in the compiler low level / RTL / manager memory?

 

(sorry if I insist, but the libraries works perfectly with dozen of delphi projects, big, a variety of components, and the problem appears only with this Delphi Cross Socket IoCompletionPort)

Edited by RDPasqua

Share this post


Link to post

I have solved with this: IsMultiThread:=True; at begin

 

but this isn't a old setting?

 

problem persist

 

just to clarify then I stop to be boring, imho the thing deserves a look, because for example using TParallel.For and other system.threadpool with massive concurrency I get no problem at all... Something of odd should be (sorry if I'm wrong)

Edited by RDPasqua

Share this post


Link to post

yes, indeed, the problem appears only using Intel TBB

 

I have tested FastMM-avx, ScaleMM2, Google tcMalloc, BrainMM

 

curiously, under Windows Server 2016, the better performing heap manager (I'm using apachebench to do a test with 1000 concurrent sockets) is the OS (using directly heapalloc, heapfree...)

 

I would like to notify IntelTBB github about their problem

 

thanks all for the help

 

btw. https://docs.microsoft.com/en-us/windows/desktop/memory/low-fragmentation-heap

Edited by RDPasqua

Share this post


Link to post
1 hour ago, RDPasqua said:

better performing

speed, min/max memory footprint, fragmentation, single/multi thread, sharing memory across threads?

Edited by Stefan Glienke

Share this post


Link to post

I have tested only the application throughput speed, I don't know if it's prone to fragmentation (probably the big advantage of adopting a MM layer is avoid this)

How to test other parameters you told?

 

(btw. I see C++ coders use msvcrt malloc or directly the OS heap allocator api)

 

https://github.com/01org/tbb/issues/120#issuecomment-459776671

https://github.com/winddriver/Delphi-Cross-Socket/issues/39

 

(I miss Per Larsen SleuthQA, I try now madExcept, or do you know any good QA mem checker?)

Edited by RDPasqua

Share this post


Link to post

I have done a quick look to the source where exception happens,

well, I have not seen errors, also the code seems very well designed with interfaces, anonymous methods, abstraction, generics, correct overloading and great management of windows api

I have done a try to resemble the function with the fault, calling a new() record within a loop, without troubles

... :-zzz

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×