Aborting a TIdHttp Connection from another thread is not thread-safe

Giganews Newsgroups
Subject: Aborting a TIdHttp Connection from another thread is not thread-safe
Posted by:  Andreas Hesse (…@ahsysteme.de)
Date: Fri, 21 May 2010

Just trying to abort long running connections in one thread from another
thread (as suggested).

Doing some stress tests I run into memory errors.
So aborting a connection from another thread is not thread-safe.

As you can see in the error from FastMM, the connecion is running in
thread 0xCBC and disconnected from thread 0xB8C.
Any chance to make it thread safe?

--
Andreas

Here is the FastMM error message:

--------------------------------2010/5/21
10:36:26--------------------------------
FastMM has detected an error during a FreeMem operation. An attempt has
been made to free/reallocate an unallocated block.

The block size is: 19800

This block was allocated by thread 0xCBC, and the stack trace (return
addresses) at the time was:
404851 [System][System.@ReallocMem]
40A674 [System][System.DynArraySetLength]
40A74A [System][System.@DynArraySetLength]
5C87B3 [IdGlobal.pas][IdGlobal][IdGlobal.ToBytes][5284]
C7A9E6 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.Write][957]
C79E86 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.Write][605]
C813EF
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadFromSource][1478]
C81853
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadBytes][1616]
C81E1F
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadStream][1797]
412CFD [FastMM4][FastMM4.DebugFreeMem]
408D65 [System][System.@UStrSetLength]

The allocation number was: 2845866

The block was previously freed by thread 0xB8C, and the stack trace
(return addresses) at the time was:
412DFD [FastMM4][FastMM4.DebugReallocMem]
40481F [System][System.@ReallocMem]
40A674 [System][System.DynArraySetLength]
C79727 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.CheckAdd][409]
40A74A [System][System.@DynArraySetLength]
C7AAA1 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.Write][970]
C79E86 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.Write][605]
C813EF
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadFromSource][1478]
5B7B5F [Log4D.pas][Log4D][Log4D.TLogLogger.DoLog][1630]
C8E61B
[IdIOHandlerStack.pas][IdIOHandlerStack][IdIOHandlerStack.TIdIOHandlerStack.Connected][230]
C87DE7
[IdTCPConnection.pas][IdTCPConnection][IdTCPConnection.TIdTCPConnection.Connected][495]

The current thread ID is 0xCBC, and the stack trace (return addresses)
leading to this error is:
412DFD [FastMM4][FastMM4.DebugReallocMem]
40481F [System][System.@ReallocMem]
40A674 [System][System.DynArraySetLength]
C79727 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.CheckAdd][409]
40A74A [System][System.@DynArraySetLength]
C7AAA1 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.Write][970]
C79E86 [IdBuffer.pas][IdBuffer][IdBuffer.TIdBuffer.Write][605]
C813EF
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadFromSource][1478]
C8ED1E
[IdIOHandlerStack.pas][IdIOHandlerStack][IdIOHandlerStack.TIdIOHandlerStack.CheckForDisconnect][395]
C81853
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadBytes][1616]
C81E1F
[IdIOHandler.pas][IdIOHandler][IdIOHandler.TIdIOHandler.ReadStream][1797]

Current memory dump of 256 bytes starting at pointer address 7DF8CB80:
CC 31 EF 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80
80 80 80 80 80 80 80 80
Ì  1  ï  .  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤
¤  ¤  ¤  ¤  ¤  ¤  ¤  ¤

Replies