Indy 10:
两个线程,线程1正在调用TIdHTTP上的Get并阻塞读取数据。线程2将在同一个TIdHTTP上调用disconnect以中断Get。
我在TIdHTTP上使用摘要认证,偶尔会出现AV。
线程1的调用堆栈:
40491D [system.pas][System][@ClassDestroy][8989]
69EF2B [..\..\common\IdAuthenticationDigest.pas][IdAuthenticationDigest][TIdDigestAuthentication.Destroy][109]
404567 [system.pas][System][TObject.Free][8313]
6A2B69 [..\..\Common\IdHTTP.pas][IdHTTP][TIdCustomHTTP.DoOnDisconnected][1587]
534574 [IdTCPConnection.pas][IdTCPConnection][TIdTCPConnection.Disconnect][532]
534B3B [IdTCPConnection.pas][IdTCPConnection][TIdTCPConnection.Disconnect][767]
6A3FB3 [..\..\Common\IdHTTP.pas][IdHTTP][TIdCustomHTTP.DoRequest][2101]
线程2的调用栈:
402BA3 [system.pas][System][@FreeMem][2477]
404521 [system.pas][System][TObject.FreeInstance][8294]
40491D [system.pas][System][@ClassDestroy][8989]
69EF2B [..\..\common\IdAuthenticationDigest.pas][IdAuthenticationDigest] [TIdDigestAuthentication.Destroy][109]
404567 [system.pas][System][TObject.Free][8313]
6A2B69 [..\..\Common\IdHTTP.pas][IdHTTP][TIdCustomHTTP.DoOnDisconnected][1587]
534574 [IdTCPConnection.pas][IdTCPConnection][TIdTCPConnection.Disconnect][532]
534B3B [IdTCPConnection.pas][IdTCPConnection][TIdTCPConnection.Disconnect][767]
基本上在DoRequest的结尾会进入到一个断开连接的状态。似乎在断开连接时存在竞争条件,尝试释放Request.Authentication。
已下载Indy 10的最新代码,并查看了代码,我认为行为应该是相同的。
我认为从另一个线程调用断开连接是推荐的使用模式,我错了吗?这是Indy中的一个bug吗?看起来需要锁定断开连接,但很难看出可能会引起的死锁。还有其他人遇到过这个问题吗?
TIdTelnet
,在内部执行的正是Mike正在做的事情。除非使用超时,否则从另一个线程断开套接字是中止阻塞I/O操作的唯一方法。 - Remy Lebeau