Skip to content

Fixes server crash when RDMA benchmark clients disconnect - #3448

Merged
zuiderkwast merged 1 commit into
valkey-io:unstablefrom
quanyeyang:fix/rdma-benchmark-lost-wakeup
May 6, 2026
Merged

zuiderkwast merged 1 commit into
valkey-io:unstablefrom
quanyeyang:fix/rdma-benchmark-lost-wakeup

Conversation

@quanyeyang

@quanyeyang quanyeyang commented Apr 6, 2026 •

Copy link
Copy Markdown
Member

Fixes server crash when RDMA benchmark clients disconnect (part of #3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

Server Crash on Client Disconnect

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash with a segmentation fault in handleReadResult, accessing address 0x8 (NULL pointer dereference).

Root Cause

The same RDMA connection could be added to pending_list multiple times, leading to use-after-free:

  1. When a client disconnects, rdmaHandleDisconnect() adds the connection to pending_list and sets conn->state = CONN_STATE_CLOSED
  2. Before rdmaProcessPendingData() processes it, event-driven callbacks (e.g., connRdmaSetWriteHandler) could add the same connection again to pending_list
  3. In rdmaProcessPendingData(), the first iteration processes and may free the connection, but the second iteration accesses the already freed connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  • valkey-benchmark creates multiple concurrent connections
  • On Ctrl+C, these connections disconnect nearly simultaneously
  • Event callbacks can re-add connections before processing completes

Stack trace from crash:

handleReadResult+0x100
readQueryFromClient+0x63
rdmaProcessPendingData (0x1b1eb9)
beforeSleep+0x82

Solution

Four targeted fixes in src/rdma.c:

  1. rdmaHandleDisconnect (line 535): Check if pending_list_node is NULL before adding to pending_list to prevent duplicates

    /* we can't close connection now, let's mark this connection as closed state */
    if (rdma_conn->pending_list_node == NULL) {
        listAddNodeTail(pending_list, conn);
        rdma_conn->pending_list_node = listLast(pending_list);
    }
  2. connRdmaSetWriteHandler (line 956): Add same check before adding to pending_list to prevent duplicates during write handler updates

    /* does this connection has pending write data? */
    if (func) {
        if (rdma_conn->pending_list_node == NULL) {
            listAddNodeTail(pending_list, conn);
            rdma_conn->pending_list_node = listLast(pending_list);
        }
    } else if (rdma_conn->pending_list_node) {
        listDelNode(pending_list, rdma_conn->pending_list_node);
        rdma_conn->pending_list_node = NULL;
    }
  3. rdmaProcessPendingData (line 1786): Use iterator node 'ln' instead of rdma_conn->pending_list_node when deleting, as the latter may have been overwritten if the connection was re-added

    listDelNode(pending_list, ln);  // Use ln, not rdma_conn->pending_list_node
    rdma_conn->pending_list_node = NULL;
  4. rdmaProcessPendingData (line 1782-1787): Reorder operations to call handlers before deleting from list, ensuring connection structure remains valid during handler execution

    if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED) {
        /* Invoke handlers first, then remove from list */
        if (callHandler(conn, conn->read_handler)) {
            callHandler(conn, conn->write_handler);
        }
    
        listDelNode(pending_list, ln);
        rdma_conn->pending_list_node = NULL;
    
        ++processed;
        continue;
    }

The fix uses pending_list_node as both a list pointer and a "already in list" flag:

  • NULL = not in list, safe to add
  • non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once, preventing use-after-free crashes.

Testing

I use ./src/valkey-benchmark --rdma -h 10.0.0.1 -t get -n 100000 -c 1 to test this:

====== GET ======                                                                  
  100000 requests completed in 4.64 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1
  host configuration "save": 3600 1 300 100 60 10000
  host configuration "appendonly": no
  multi-thread: no

Latency by percentile distribution:
0.000% <= 0.007 milliseconds (cumulative count 4601)
50.000% <= 0.023 milliseconds (cumulative count 98267)
98.438% <= 0.031 milliseconds (cumulative count 99802)
99.805% <= 0.039 milliseconds (cumulative count 99886)
99.902% <= 0.055 milliseconds (cumulative count 99907)
99.951% <= 0.199 milliseconds (cumulative count 99954)
99.976% <= 0.215 milliseconds (cumulative count 99977)
99.988% <= 0.239 milliseconds (cumulative count 99991)
99.994% <= 0.255 milliseconds (cumulative count 99997)
99.998% <= 0.463 milliseconds (cumulative count 99999)
99.999% <= 0.935 milliseconds (cumulative count 100000)
100.000% <= 0.935 milliseconds (cumulative count 100000)

Cumulative distribution of latencies:
99.934% <= 0.103 milliseconds (cumulative count 99934)
99.965% <= 0.207 milliseconds (cumulative count 99965)
99.998% <= 0.303 milliseconds (cumulative count 99998)
99.999% <= 0.503 milliseconds (cumulative count 99999)
100.000% <= 1.007 milliseconds (cumulative count 100000)

Summary:
  throughput summary: 21561.02 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        0.016     0.000     0.023     0.023     0.031     0.935

@quanyeyang quanyeyang changed the title Signed-off-by: Ada-Church-Closure <[email protected]> Fix RDMA benchmark GET lost wakeup issue (#3345) Apr 6, 2026
@quanyeyang quanyeyang changed the title Fix RDMA benchmark GET lost wakeup issue (#3345) Fix RDMA benchmark GET lost wakeup issue Apr 6, 2026
@codecov

codecov Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.57%. Comparing base (c0289c6) to head (782f472).
⚠️ Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3448      +/-   ##
============================================
+ Coverage     76.53%   76.57%   +0.03%     
============================================
  Files           157      157              
  Lines         79045    79048       +3     
============================================
+ Hits          60501    60529      +28     
+ Misses        18544    18519      -25     
Files with missing lines Coverage Δ
src/rdma.c 100.00% <ø> (ø)

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@quanyeyang

Copy link
Copy Markdown
Member Author

@pizhenwei take a loot at this? thanks!

Comment thread deps/libvalkey/src/rdma.c Resolved
Comment thread deps/libvalkey/src/rdma.c Resolved
Comment thread deps/libvalkey/src/rdma.c Resolved
Comment thread deps/libvalkey/src/rdma.c Resolved
Comment thread src/valkey-benchmark.c Resolved
Comment thread src/valkey-benchmark.c Resolved
Comment thread src/valkey-benchmark.c Resolved

@pizhenwei pizhenwei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 independent fixes in this PR, I suggest that to fix the unexpected crash (src/rdma.c) only in this PR. And open a new PR to fix src/valkey-benchmark.c.

I believe that you point out the root cause of losing wakeup event in the client side, I guess it's also possible to lose wakeup event in current fix (deps/libvalkey/src/rdma.c), I'll also open a new PR to discuss it later.

pizhenwei

This comment was marked as spam.

pizhenwei

This comment was marked as spam.

pizhenwei

This comment was marked as spam.

@quanyeyang
quanyeyang force-pushed the fix/rdma-benchmark-lost-wakeup branch from e4ab963 to 5933bbc Compare April 12, 2026 13:25
quanyeyang added a commit to quanyeyang/valkey that referenced this pull request Apr 12, 2026
Per review feedback in PR valkey-io#3448, splitting this PR to focus only on
the server-side crash fix in src/rdma.c:
- deps/libvalkey/src/rdma.c: Maintainer will address in separate PR
- src/valkey-benchmark.c: Will be submitted in new PR for client-side fix

This PR now contains only the server-side RDMA connection crash fix.
@quanyeyang quanyeyang changed the title Fix RDMA benchmark GET lost wakeup issue Fixes server crash when RDMA benchmark clients disconnect Apr 12, 2026
quanyeyang added a commit to quanyeyang/valkey that referenced this pull request Apr 12, 2026
Per review feedback in PR valkey-io#3448, splitting this PR to focus only on
the server-side crash fix in src/rdma.c:
- deps/libvalkey/src/rdma.c: Maintainer will address in separate PR
- src/valkey-benchmark.c: Will be submitted in new PR for client-side fix

This PR now contains only the server-side RDMA connection crash fix.

Signed-off-by: Ada-Church-Closure <[email protected]>
@quanyeyang
quanyeyang force-pushed the fix/rdma-benchmark-lost-wakeup branch from 5933bbc to 7c96a6f Compare April 12, 2026 13:43
When RDMA benchmark clients disconnect (e.g., via Ctrl+C), the server
could crash with SIGSEGV due to connections being added to pending_list
multiple times, leading to use-after-free.

Root Cause:
-----------
The same RDMA connection could be added to pending_list multiple times:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
   to pending_list and sets conn->state = CONN_STATE_CLOSED

2. Before rdmaProcessPendingData() processes it, event-driven callbacks
   (e.g., connRdmaSetWriteHandler) could add the same connection again

3. In rdmaProcessPendingData(), the first iteration may free the connection,
   but the second iteration accesses the freed connection → SIGSEGV at 0x8

The problem was exacerbated because valkey-benchmark creates multiple
concurrent connections that disconnect nearly simultaneously on Ctrl+C,
and event callbacks can re-add connections before processing completes.

Solution:
---------
Four targeted fixes in src/rdma.c ensure each connection appears in
pending_list at most once by using pending_list_node as both a list
pointer and an "already in list" flag:

1. rdmaHandleDisconnect (line 535): Check if pending_list_node is NULL
   before adding to prevent duplicates

2. connRdmaSetWriteHandler (line 958): Add same check before adding
   during write handler updates

3. rdmaProcessPendingData (line 1790): Use iterator node 'ln' instead
   of rdma_conn->pending_list_node when deleting, as the latter may
   have been overwritten if connection was re-added

4. rdmaProcessPendingData (line 1783-1790): Call handlers before
   removing from list to ensure connection structure remains valid

Fixes valkey-io#3345

Signed-off-by: Ada-Church-Closure <[email protected]>
@quanyeyang
quanyeyang force-pushed the fix/rdma-benchmark-lost-wakeup branch from 7c96a6f to 782f472 Compare April 12, 2026 13:46

@pizhenwei pizhenwei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@sarthakaggarwal97

Copy link
Copy Markdown
Contributor

Taking a look

Comment thread src/rdma.c
returns 0, indicating the connection has closed, in which case
write_handler will be skipped. */
if (callHandler(conn, conn->read_handler)) {
callHandler(conn, conn->write_handler);

@sarthakaggarwal97 sarthakaggarwal97 Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the callHandler here is readQueryFromClient. This call handler can free the RDMA connection if connection is in disconnect state via this flow: readQueryFromClient -> handleReadResult -> freeClientAsync -> close_asap?

So it's possible that the before the callHandler is completed, the RDMA connection is already free? Then could it be an issue on how are we clearing the pending_list ahead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I traced through the code path carefully,and if I miss something,please correct me.
freeClientAsync only enqueues the client to server.clients_to_close and sets close_asap = 1. The actual freeClient → connClose → zfree(conn) happens later in freeClientsInAsyncFreeQueue(), which is called after rdmaProcessPendingData() returns in beforeSleep().
Additionally, callHandler would only trigger an immediate connClose if CONN_FLAG_CLOSE_SCHEDULED is set, which only happens when connClose() is called directly while refs > 0. That does not occur in the readQueryFromClient → freeClientAsync path.
Therefore rdma_conn remains valid after callHandler returns, and the subsequent listDelNode pending_list_node = NULL is safe.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sarthakaggarwal97, just a gentle ping on this. Please let me know if my previous explanation regarding the freeClientAsync path addresses your concern, or if you have any other questions. Happy to make changes if needed!

@zuiderkwast

Copy link
Copy Markdown
Contributor

Which versions do we need to backport this to? Is it 9.1, 9.0 and 8.1?

@pizhenwei

Copy link
Copy Markdown
Contributor

Which versions do we need to backport this to? Is it 9.1, 9.0 and 8.1?

This issue was introduced since the initial version, 9.1, 9.0 and 8.1 are needed to fix.

@zuiderkwast
zuiderkwast merged commit 75fee11 into valkey-io:unstable May 6, 2026
57 of 58 checks passed
@github-project-automation github-project-automation Bot moved this to To be backported in Valkey 8.1 May 6, 2026
@github-project-automation github-project-automation Bot moved this to To be backported in Valkey 9.1 May 6, 2026
@github-project-automation github-project-automation Bot moved this to To be backported in Valkey 9.0 May 6, 2026
@quanyeyang
quanyeyang deleted the fix/rdma-benchmark-lost-wakeup branch May 7, 2026 04:21
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request May 7, 2026
…3448)

Fixes server crash when RDMA benchmark clients disconnect (part of
valkey-io#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
sarthakaggarwal97 pushed a commit to sarthakaggarwal97/valkey that referenced this pull request May 7, 2026
…3448)

Fixes server crash when RDMA benchmark clients disconnect (part of
valkey-io#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
lucasyonge pushed a commit that referenced this pull request May 11, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
lucasyonge pushed a commit that referenced this pull request May 12, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
@sarthakaggarwal97 sarthakaggarwal97 moved this from To be backported to Done in Valkey 9.1 May 16, 2026
valkeyrie-ops Bot pushed a commit that referenced this pull request May 18, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
valkeyrie-ops Bot pushed a commit that referenced this pull request May 19, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
zuiderkwast pushed a commit that referenced this pull request Jun 2, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Jun 2, 2026
@zuiderkwast zuiderkwast moved this from To be backported to 8.1.8 (WIP) in Valkey 8.1 Jun 2, 2026
zuiderkwast pushed a commit that referenced this pull request Jun 2, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
valkeyrie-ops Bot pushed a commit that referenced this pull request Jun 16, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
sarthakaggarwal97 pushed a commit that referenced this pull request Jul 14, 2026
Fixes server crash when RDMA benchmark clients disconnect (part of
#3345).

This PR focuses on the server-side crash fix. The benchmark
client-side fix will be submitted in a separate PR.

## Server Crash on Client Disconnect 

​ When interrupting valkey-benchmark with Ctrl+C, the server would crash
with a segmentation fault in handleReadResult, accessing address 0x8
(NULL pointer dereference).

### Root Cause

The same RDMA connection could be added to pending_list multiple times,
leading to use-after-free:

1. When a client disconnects, rdmaHandleDisconnect() adds the connection
to pending_list and sets conn->state = CONN_STATE_CLOSED
2. Before rdmaProcessPendingData() processes it, event-driven callbacks
(e.g., connRdmaSetWriteHandler) could add the same connection again to
pending_list
3. In rdmaProcessPendingData(), the first iteration processes and may
free the connection, but the second iteration accesses the already freed
connection → SIGSEGV at address 0x8 (NULL + offset)

The problem was exacerbated because:

  - valkey-benchmark creates multiple concurrent connections
  - On Ctrl+C, these connections disconnect nearly simultaneously
  - Event callbacks can re-add connections before processing completes

 **Stack trace from crash:**

  	handleReadResult+0x100
  	readQueryFromClient+0x63
  	rdmaProcessPendingData (0x1b1eb9)
  	beforeSleep+0x82

### Solution

 Four targeted fixes in `src/rdma.c`:

1. `rdmaHandleDisconnect (line 535)`: Check if pending_list_node is NULL
before adding to pending_list to prevent duplicates

   ```C
/* we can't close connection now, let's mark this connection as closed
state */
   if (rdma_conn->pending_list_node == NULL) {
       listAddNodeTail(pending_list, conn);
       rdma_conn->pending_list_node = listLast(pending_list);
   }
   ```

2. `connRdmaSetWriteHandler (line 956)`: Add same check before adding to
pending_list to prevent duplicates during write handler updates

   ```C
   /* does this connection has pending write data? */
   if (func) {
       if (rdma_conn->pending_list_node == NULL) {
           listAddNodeTail(pending_list, conn);
           rdma_conn->pending_list_node = listLast(pending_list);
       }
   } else if (rdma_conn->pending_list_node) {
       listDelNode(pending_list, rdma_conn->pending_list_node);
       rdma_conn->pending_list_node = NULL;
   }
   ```

3. `rdmaProcessPendingData (line 1786)`: Use iterator node 'ln' instead
of rdma_conn->pending_list_node when deleting, as the latter may have
been overwritten if the connection was re-added

   ```C
listDelNode(pending_list, ln); // Use ln, not
rdma_conn->pending_list_node
   rdma_conn->pending_list_node = NULL;
   ```

4. `rdmaProcessPendingData (line 1782-1787)`: Reorder operations to call
handlers before deleting from list, ensuring connection structure
remains valid during handler execution

   ```C
if (conn->state == CONN_STATE_ERROR || conn->state == CONN_STATE_CLOSED)
{
       /* Invoke handlers first, then remove from list */
       if (callHandler(conn, conn->read_handler)) {
           callHandler(conn, conn->write_handler);
       }

       listDelNode(pending_list, ln);
       rdma_conn->pending_list_node = NULL;

       ++processed;
       continue;
   }
   ```

The fix uses **pending_list_node** as both a list pointer and a
"**already in list**" flag:

  - NULL = not in list, safe to add
  - non-NULL = already in list, skip adding

This ensures each connection appears in pending_list at most once,
preventing use-after-free crashes.

Signed-off-by: Ada-Church-Closure <[email protected]>
@valkeyrie-ops valkeyrie-ops Bot moved this from To be backported to Done in Valkey 9.0 Jul 14, 2026
@sarthakaggarwal97 sarthakaggarwal97 moved this to To be backported in Valkey 8.0 Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes This issue should get a line item in the release notes

Projects

Status: To be backported
Status: 8.1.8
Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants