Skip to content

Commit

Permalink
Socket leak when VM stop/start In loop
Browse files Browse the repository at this point in the history
When VIF is added but not connected, vru_cl->vruc_fd is not added to the
fd list even though it is created. This can happen when VM is stopped.
In this case, vr_uvhost_del_fds_by_arg() would not close
the fd. This leads to socket leak, so added fcntl() call in
vr_uvhost_del_client() to check if vruc_fd is closed or not.
Closes-jira-bug: CEM-9285

Change-Id: Ia55e44b8830b96e8313691dc77873bfd133e1469
  • Loading branch information
hajimohamed authored and kirankn80 committed Mar 10, 2020
1 parent 3b04d0c commit 194c8bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dpdk/vr_uvhost_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ vr_uvhost_del_client(vr_uvh_client_t *vru_cl)
/* Remove both the socket we listen for and the socket we have accepted */
vr_uvhost_del_fds_by_arg(vru_cl);

/* If a VIF is added but not connected, vru_cl->vruc_fd is not added to
* the fd list even though it is created. This can happen when VM is
* stopped. In this case, vr_uvhost_del_fds_by_arg() would not close
* the fd. So, add the fcntl() call below to check if vruc_fd is closed
* or not.
* */
if(fcntl(vru_cl->vruc_fd, F_GETFL) != -1 ){
vr_uvhost_log("Closing socket fd: %d \n", vru_cl->vruc_fd);
close(vru_cl->vruc_fd);
}

vru_cl->vruc_fd = -1;
if (vru_cl->vruc_vhostuser_mode == VRNU_VIF_MODE_CLIENT)
unlink(vru_cl->vruc_path);
Expand Down
6 changes: 5 additions & 1 deletion dpdk/vr_uvhost_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,11 @@ vr_uvh_cl_timer_handler(int fd, void *arg)
if (ret == -1) {
RTE_LOG_DP(DEBUG, UVHOST, "Error connecting uvhost socket FD %d to %s:"
" %s (%d)\n", vru_cl->vruc_fd, sun.sun_path, rte_strerror(errno), errno);
ret = vr_uvh_cl_timer_setup(vru_cl);
/* Check the interface is connected or not.
* Avoiding race condition where tap interface already connected */
if(errno != EISCONN)
ret = vr_uvh_cl_timer_setup(vru_cl);

} else {

vr_uvhost_log(" connected to %s for uvhost socket FD %d\n",
Expand Down
1 change: 1 addition & 0 deletions dpdk/vr_uvhost_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef __VR_UVHOST_MSG_H__
#define __VR_UVHOST_MSG_H__

#include <fcntl.h>
#include "vr_dpdk_virtio.h"
#include "vr_dpdk.h"
/*
Expand Down

0 comments on commit 194c8bc

Please sign in to comment.