Skip to content

Find Bug from tncLine.pas #42

Description

@jiangwei7480

hello:
I found a bug in the DestroyHandle function of the TncLine class, as shown in the following code:
delphi
procedure TncLine.DestroyHandle;
begin
if FActive then
begin
try
{$IFDEF MSWINDOWS}
Shutdown(FHandle, SD_BOTH);
CloseSocket(FHandle);
{$ELSE}
Shutdown(FHandle, SHUT_RDWR);
Posix.Unistd.__Close(FHandle);
{$ENDIF}
except
end;
try
SetDisconnected;
except
end;

FHandle := InvalidSocket;

end;
end;
When connecting to a service that is not running, the connection fails and triggers repeated reconnection attempts due to timeout, which will cause the socket buffer to freeze. The root cause is the if FActive then condition check inside the DestroyHandle function: the connection has not been successfully established at this point, so the created socket handle is not released.
I have edit it, It is:
try
{$IFDEF MSWINDOWS}
Shutdown(FHandle, SD_BOTH);
CloseSocket(FHandle);
{$ELSE}
Shutdown(FHandle, SHUT_RDWR);
Posix.Unistd.__Close(FHandle);
{$ENDIF}
except
end;
Try
try
if FActive then SetDisconnected;
except
end;
finally
FHandle := InvalidSocket;
end;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions