Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

socket is never closed when connect() failed. #35

Open
matao403 opened this issue May 12, 2017 · 1 comment
Open

socket is never closed when connect() failed. #35

matao403 opened this issue May 12, 2017 · 1 comment

Comments

@matao403
Copy link
Contributor

matao403 commented May 12, 2017

This issue exists in 1.1.0, 2.0.0 and master.   In __apn_connect function, if connect failed, sock is not set to ctx->sock, application level apn_close() can not close this socket. If application always retry to create connection, it will cause a lot of unclosed socket. Every process used socket is limited, after socket is exhausted, all file/socket operation will be failed. This issue is seen when DNS is ok, but apn traffic is blocked by firewall. 
The fix is easy, add close socket in connect() error branch.

__apn_connect()
...
if (connect(sock, (struct sockaddr *) &socket_address, sizeof (socket_address)) < 0) {
APN_SET_ERROR(error, APN_ERR_COULD_NOT_INITIALIZE_CONNECTION | APN_ERR_CLASS_INTERNAL, __apn_errors[APN_ERR_COULD_NOT_INITIALIZE_CONNECTION]);
APN_RETURN_ERROR;
}

    ctx->sock = sock;
@matao403
Copy link
Contributor Author

@adobkin Can you have a look at this issue? I have created 2 pull requests in both 1.1.0 and 2.0.0. I'm waiting for your acceptance. If you can accept it, I don't use a patch in local build.

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

No branches or pull requests

1 participant