Skip to content

Commit

Permalink
RDMA: Delete keepalive timer on closing (#1237)
Browse files Browse the repository at this point in the history
Typically, RDMA connection gets closed by client side, the server side
handles diconnected CM event, and delete keepalive timer correctly.
However, the server side may close connection voluntarily, for example
the maxium connections exceed. Handle this case to avoid invalid memory
access.

Signed-off-by: zhenwei pi <[email protected]>
  • Loading branch information
pizhenwei authored Oct 30, 2024
1 parent 789a73b commit ab98f37
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/rdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,22 @@ static int rdmaHandleEstablished(struct rdma_cm_event *ev) {
return C_OK;
}

static inline void rdmaDelKeepalive(aeEventLoop *el, RdmaContext *ctx) {
if (ctx->keepalive_te == AE_ERR) {
return;
}

aeDeleteTimeEvent(el, ctx->keepalive_te);
ctx->keepalive_te = AE_ERR;
}

static int rdmaHandleDisconnect(aeEventLoop *el, struct rdma_cm_event *ev) {
struct rdma_cm_id *cm_id = ev->id;
RdmaContext *ctx = cm_id->context;
connection *conn = ctx->conn;
rdma_connection *rdma_conn = (rdma_connection *)conn;

aeDeleteTimeEvent(el, ctx->keepalive_te);
rdmaDelKeepalive(el, ctx);
conn->state = CONN_STATE_CLOSED;

/* we can't close connection now, let's mark this connection as closed state */
Expand Down Expand Up @@ -1173,6 +1182,7 @@ static void connRdmaClose(connection *conn) {
}

ctx = cm_id->context;
rdmaDelKeepalive(server.el, ctx);
rdma_disconnect(cm_id);

/* poll all CQ before close */
Expand Down

0 comments on commit ab98f37

Please sign in to comment.