Bug 576551 - close(socket) needed to avoid socket resource leakage
Summary: close(socket) needed to avoid socket resource leakage
Status: CLOSED FIXED
Alias: None
Product: 4DIAC
Classification: IoT
Component: FORTE (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 major
Target Milestone: 2.0.1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-11 01:32 EDT by xin zhao CLA
Modified: 2021-11-15 09:52 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description xin zhao CLA 2021-10-11 01:32:27 EDT
We are doing a FBN with a http client and there is FBs to re initialize when the server cannot be connected. (a little bit strange for http connection as the communication failure would release the protocol stack)

After long time test, we found that the socket resource are all consumed as no more connection could be initiated for all the applications in windows 10.

I dig a litte bit into the code and I think there should be closeSocket(nSocket) in the below code snippet.

Win32SocketInterface::TSocketDescriptor CWin32SocketInterface::openTCPClientConnection(char *pa_acIPAddr, unsigned short pa_nPort){
.......
    if(SOCKET_ERROR == connect(nSocket, (struct sockaddr*) &stSockAddr, sizeof(struct sockaddr))) {
      int nLastError = WSAGetLastError();
      LPSTR pacErrorMessage = getErrorMessage(nLastError);
      DEVLOG_ERROR("CWin32SocketInterface: connect() failed: %d - %s\n", nLastError, pacErrorMessage);
      LocalFree(pacErrorMessage);
      closeSocket(nSocket);
    }
    else{
      nRetVal = nSocket;
    }
.......
Comment 1 xin zhao CLA 2021-10-11 01:33:14 EDT
besides, I checked the couterpart of bsd socket realization and there is close(socket) at the similar postion.
Comment 2 Martin Melik-Merkumians CLA 2021-10-11 06:37:57 EDT
Hi.

Good spot, the socket should be closed there also.
One comment, for WinSock the function to close a socket is closesocket (all lower case) 

https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-closesocket

Best regards,
Martin
Comment 3 xin zhao CLA 2021-10-11 06:51:40 EDT
yes, (In reply to Martin Melik-Merkumians from comment #2)
> Hi.
> 
> Good spot, the socket should be closed there also.
> One comment, for WinSock the function to close a socket is closesocket (all
> lower case) 
> 
> https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-
> closesocket
> 
> Best regards,
> Martin

yes, Martin, thanks for the information. 

Somebody made a function  in win32socketinterf.cpp called closeSocket and inside it calls closesocket. :)
Comment 4 Eclipse Genie CLA 2021-10-18 03:46:17 EDT
New Gerrit change created: https://git.eclipse.org/r/c/4diac/org.eclipse.4diac.forte/+/186579