Skip to content

Commit

Permalink
prov/shm: Close device_fds for connected peers when the EP is closed
Browse files Browse the repository at this point in the history
This fixes a file descriptor leak which is not obvious for regular
applications. For fi_ubertest, however, each sub-test goes through
a setup-teardown process the file descriptors can quickly run out
due to this leak.

Cherry-picked from commit b555e51

Signed-off-by: Jianxin Xiong <[email protected]>
  • Loading branch information
j-xiong authored and aingerson committed Mar 18, 2024
1 parent 9bc355c commit 9d4692d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions prov/shm/src/smr_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,21 @@ static void smr_cleanup_epoll(struct smr_sock_info *sock_info)
ofi_epoll_close(sock_info->epollfd);
}

static void smr_free_sock_info(struct smr_ep *ep)
{
int i, j;

for (i = 0; i < SMR_MAX_PEERS; i++) {
if (!ep->sock_info->peers[i].device_fds)
continue;
for (j = 0; j < ep->sock_info->nfds; j++)
close(ep->sock_info->peers[i].device_fds[j]);
free(ep->sock_info->peers[i].device_fds);
}
free(ep->sock_info);
ep->sock_info = NULL;
}

static int smr_ep_close(struct fid *fid)
{
struct smr_ep *ep;
Expand All @@ -826,7 +841,7 @@ static int smr_ep_close(struct fid *fid)
close(ep->sock_info->listen_sock);
unlink(ep->sock_info->name);
smr_cleanup_epoll(ep->sock_info);
free(ep->sock_info);
smr_free_sock_info(ep);
}

if (ep->srx && ep->util_ep.ep_fid.msg != &smr_no_recv_msg_ops)
Expand Down Expand Up @@ -1173,19 +1188,6 @@ void smr_ep_exchange_fds(struct smr_ep *ep, int64_t id)
SMR_CMAP_FAILED : SMR_CMAP_SUCCESS;
}

static void smr_free_sock_info(struct smr_ep *ep)
{
int i, j;

for (i = 0; i < SMR_MAX_PEERS; i++) {
for (j = 0; j < ep->sock_info->nfds; j++)
close(ep->sock_info->peers[i].device_fds[j]);
free(ep->sock_info->peers[i].device_fds);
}
free(ep->sock_info);
ep->sock_info = NULL;
}

static void smr_init_ipc_socket(struct smr_ep *ep)
{
struct smr_sock_name *sock_name;
Expand Down

0 comments on commit 9d4692d

Please sign in to comment.