LNet Memory Leak lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- ttomas · 2012-12-12 13:12 I stress test LNet http server with DDoS attack tool LOIC http://sourceforge.net/projects/loic/ Without DDoS attack there is no memory leak in http server. With LOIC attack with 100 threads and when failed packets start to increase we have 1024 bytes leak on every failed request. Memory leak is from lnet.pas unit Code: [Select]procedure TLTcp.AcceptAction(aSocket: TLHandle); var   Tmp: TLSocket; begin   Tmp := InitSocket(SocketClass.Create);  <<<< TLSocket is allocated but never free. This is not only http server problem, TCPServer is also effected. After and in time of attack server work without problems with browser, but memory increase and with long time attack we will have out of memory. I attach small demo project for testing. Windows 7 64b and 32b, I use Lazarus 1.1 CodeTyphon 3.10, LNet source is same with svn trunk. I open in bug tracker http://mantis.freepascal.org/view.php?id=23475 ---------------------------------------------------------------------- Almindor · 2012-12-12 16:44 Thanks, I think it's a soft-disconnect problem when the other side doesn't follow protocol. I'll have to reproduce and see what can be done. ---------------------------------------------------------------------- ttomas · 2012-12-13 09:09 Other side protocol of communication is OK. Memory leak can be reproduced also with Apache benchmark tool. With AB there is no failed request. Also performance is not so good for async server 24.99 req/s. ab -n 100 -c 10 http://127.0.0.1:8088/index.html This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient).....done Server Software: Server Hostname:        127.0.0.1 Server Port:            8088 Document Path:          /index.html Document Length:        11 bytes Concurrency Level:      10 Time taken for tests:   4.002 seconds Complete requests:      100 Failed requests:        0 Write errors:           0 Total transferred:      17700 bytes HTML transferred:       1100 bytes Requests per second:    24.99 [#/sec] (mean) Time per request:       400.223 [ms] (mean) Time per request:       40.022 [ms] (mean, across all concurrent requests) Transfer rate:          4.32 [Kbytes/sec] received Connection Times (ms)               min  mean[+/-sd] median   max Connect:        0   40 135.5      0     497 Processing:     0  360 224.1    499     500 Waiting:        0  319 239.4    497     500 Total:          1  400 199.6    499     501 Percentage of the requests served within a certain time (ms)   50%    499   66%    499   75%    499   80%    499   90%    500   95%    500   98%    500   99%    501  100%    501 (longest request) With Keep Alive no memory leak ab -k -n 100 -c 10 http://127.0.0.1:8088/index.html ~3000 req/sec ab -k -n 1000 -c 100 http://127.0.0.1:8088/index.html Crash the server External SIGSEGV In file lhttp.pp at line 1450 FCurrentOutput:=FCurrentOutput.FNext;