Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCrossWebSocket对象已经被释放掉,依然触发了_OnOpenResponse事件导致非法访问的异常。 #150

Open
wqmeng opened this issue Nov 17, 2024 · 2 comments

Comments

@wqmeng
Copy link

wqmeng commented Nov 17, 2024

当应用退出的时候,释放客户端的websocket,依然会触发OnResponse事件,导致非法访问的异常,此时websocket client对象已经被释放掉了。

First chance exception at $0127D4EC. Exception class $C0000005 with message 'access violation at 0x0127d4ec: read of address 0x00000000'. Process (72684)

报错代码位于 _Lock; 此时 TCrossWebSocket Self 指针已经是不可访问的对象了。并且此时的 FStatus 也已经是非法数据 Out of bound 垃圾的越界值,使用 if (FStatus = wsShutdown) then Exit; 判断,并不能起到实际作用。

不知是我哪里的处理的顺序有问题? 还是什么错误导致?

关闭代码是:
__WebSocket.Close;
__WebSocket := nil;

procedure TCrossWebSocket._OnOpenResponse(const AResponse: ICrossHttpClientResponse);
var
  LOnOpenResponseEvents: TArray<TWsClientOnOpenResponse>;
  LOnOpenResponseEvent: TWsClientOnOpenResponse;
begin
  if (FStatus = wsShutdown) then Exit;

  _Lock;
  try
    LOnOpenResponseEvents := FOnOpenResponseEvents.ToArray;
  finally
    _Unlock;
  end;

  for LOnOpenResponseEvent in LOnOpenResponseEvents do
    if Assigned(LOnOpenResponseEvent) then
      LOnOpenResponseEvent(AResponse);
end;

Net.CrossWebSocketClient.TCrossWebSocket._OnOpenResponse(TCrossHttpClientResponse($1CAC0BA8) as ICrossHttpClientResponse)
Net.CrossWebSocketClient.TCrossWebSocket.Open$ActRec.$1$Body(TCrossHttpClientResponse($1CAC0BA8) as ICrossHttpClientResponse)
Net.CrossHttpClient.TServerDock.DoRequest[0]$ActRec.$0$Body(TCrossHttpClientResponse($1CAC0BA8) as ICrossHttpClientResponse)
Net.CrossHttpClient.TCrossHttpClientRequest.SendNoCompress[0]$ActRec.$2$Body(TCrossHttpClientResponse($1CAC0BA8) as ICrossHttpClientResponse)
Net.CrossHttpClient.TCrossHttpClientResponse.TriggerResponseFailed(400,'Connection lost')
Net.CrossHttpClient.TCrossHttpClientSocket.LogicDisconnected(TCrossWebSocketClientConnection($9048570) as ICrossConnection)
Net.CrossWebSocketClient.TCrossWebSocketClient.LogicDisconnected(TCrossWebSocketClientConnection($9048570) as ICrossConnection)
Net.CrossSocket.Base.TCrossSocketBase.TriggerDisconnected(TCrossWebSocketClientConnection($9048570) as ICrossConnection)
Net.CrossSocket.Base.TCrossConnectionBase.Close
Net.CrossSocket.Base.TCrossSocketBase.CloseAllConnections
Net.CrossSocket.Base.TCrossSocketBase.CloseAll
Net.CrossSocket.Iocp.TIocpCrossSocket.StopLoop
Net.CrossWebSocketClient.TCrossWebSocketMgr.Destroy
System.TInterfacedObject._Release
System._IntfClear(???)
:007f1537 @IntfClear + $13
@winddriver
Copy link
Owner

请提供能重现问题的工程源码

@wqmeng
Copy link
Author

wqmeng commented Nov 18, 2024

发现比较容易出现这个问题的情况就是 一个客户端,一个服务端, 如果服务端没有启动,客户端打开不久就关闭,容易出现这个问题。可能是因为有超时处理,但是此时客户端退出,会出这个异常。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants