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

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

@matao403

Description

@matao403
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;

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