From 7f51d8ae2ffc8ffd390c7be3f277d4bca24e1f7b Mon Sep 17 00:00:00 2001 From: "debing.sun" Date: Sun, 29 Mar 2026 11:09:10 +0800 Subject: [PATCH 1/4] Test tcp deadlock fixes --- tests/cluster/tests/17-diskless-load-swapdb.tcl | 9 ++++++--- tests/helpers/gen_write_load.tcl | 15 ++++++++++++++- tests/unit/memefficiency.tcl | 13 ++++++++----- tests/unit/type/set.tcl | 10 +++++++++- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/tests/cluster/tests/17-diskless-load-swapdb.tcl b/tests/cluster/tests/17-diskless-load-swapdb.tcl index cb81b9fdbd0..b25db393098 100644 --- a/tests/cluster/tests/17-diskless-load-swapdb.tcl +++ b/tests/cluster/tests/17-diskless-load-swapdb.tcl @@ -54,9 +54,12 @@ test "Main db not affected when fail to diskless load" { set rd [redis_deferring_client redis $master_id] for {set j 0} {$j < $num} {incr j} { $rd set $j $value - } - for {set j 0} {$j < $num} {incr j} { - $rd read + + if {($j + 1) % 500 == 0} { + for {set i 0} {$i < 500} {incr i} { + $rd read + } + } } # Start the replica again diff --git a/tests/helpers/gen_write_load.tcl b/tests/helpers/gen_write_load.tcl index 7b4975c61a9..085ae3f8dd6 100644 --- a/tests/helpers/gen_write_load.tcl +++ b/tests/helpers/gen_write_load.tcl @@ -22,13 +22,18 @@ proc gen_write_load {host port seconds tls {key ""} {size 0} {sleep 0}} { set start_time [clock seconds] set r [redis $host $port 1 $tls] $r client setname LOAD_HANDLER - catch {$r select 9} ;# select 9 will fail in cluster mode + $r read + catch { + $r select 9 + $r read + } ;# select 9 will fail in cluster mode # fixed size value if {$size != 0} { set value [string repeat "x" $size] } + set count 0 while 1 { if {$size == 0} { set value [expr rand()] @@ -39,6 +44,14 @@ proc gen_write_load {host port seconds tls {key ""} {size 0} {sleep 0}} { } else { $r set $key $value } + + incr count + if {$count % 500 == 0} { + for {set i 0} {$i < 500} {incr i} { + $r read + } + } + if {[clock seconds]-$start_time > $seconds} { exit 0 } diff --git a/tests/unit/memefficiency.tcl b/tests/unit/memefficiency.tcl index 6be0ed69dcf..0ab12c6c7e4 100644 --- a/tests/unit/memefficiency.tcl +++ b/tests/unit/memefficiency.tcl @@ -24,9 +24,12 @@ proc test_memory_efficiency {range} { incr written [string length $key] incr written [string length $val] incr written 2 ;# A separator is the minimum to store key-value data. - } - for {set j 0} {$j < 10000} {incr j} { - $rd read ; # Discard replies + + if {($j + 1) % 500 == 0} { + for {set i 0} {$i < 500} {incr i} { + $rd read ; # Discard replies + } + } } set current_mem [s used_memory] @@ -352,7 +355,7 @@ run_solo {defrag} { # create big keys with 10k items # Use batching to avoid TCP deadlock set rd [redis_deferring_client] - set batch_size 1000 + set batch_size 100 for {set j 0} {$j < 10000} {incr j} { $rd hset bighash $j [concat "asdfasdfasdf" $j] $rd lpush biglist [concat "asdfasdfasdf" $j] @@ -937,7 +940,7 @@ run_solo {defrag} { $rd lpush biglist2 $val incr count - discard_replies_every $rd $count 10000 20000 + discard_replies_every $rd $count 1000 2000 } # create some fragmentation diff --git a/tests/unit/type/set.tcl b/tests/unit/type/set.tcl index ae315844d60..5c38056433f 100644 --- a/tests/unit/type/set.tcl +++ b/tests/unit/type/set.tcl @@ -1027,10 +1027,18 @@ foreach type {single multiple single_multiple} { } } r deferred 1 + set count 0 foreach m $members { r srem $myset $m + incr count + if {$count == 500} { + for {set i 0} {$i < 500} {incr i} { + r read + } + set count 0 + } } - foreach m $members { + for {set i 0} {$i < $count} {incr i} { r read } r deferred 0 From ec71b0ba03ab64f3776719865995db87b487e4c2 Mon Sep 17 00:00:00 2001 From: "debing.sun" Date: Mon, 30 Mar 2026 09:36:41 +0800 Subject: [PATCH 2/4] Fix memory leak in functionsLibCtxClear function --- tests/helpers/gen_write_load.tcl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/helpers/gen_write_load.tcl b/tests/helpers/gen_write_load.tcl index 085ae3f8dd6..5ae25e1881a 100644 --- a/tests/helpers/gen_write_load.tcl +++ b/tests/helpers/gen_write_load.tcl @@ -59,6 +59,13 @@ proc gen_write_load {host port seconds tls {key ""} {size 0} {sleep 0}} { after $sleep } } + + # Discard remaining replies + if {$count != 0} { + for {set i 0} {$i < $count} {incr i} { + $r read + } + } } gen_write_load [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] [lindex $argv 4] [lindex $argv 5] [lindex $argv 6] From 349bc321878ff8a2df912905f7af2add10567c34 Mon Sep 17 00:00:00 2001 From: "debing.sun" Date: Mon, 30 Mar 2026 09:52:20 +0800 Subject: [PATCH 3/4] Don't read the unread replies when leave --- tests/helpers/gen_write_load.tcl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/helpers/gen_write_load.tcl b/tests/helpers/gen_write_load.tcl index 5ae25e1881a..085ae3f8dd6 100644 --- a/tests/helpers/gen_write_load.tcl +++ b/tests/helpers/gen_write_load.tcl @@ -59,13 +59,6 @@ proc gen_write_load {host port seconds tls {key ""} {size 0} {sleep 0}} { after $sleep } } - - # Discard remaining replies - if {$count != 0} { - for {set i 0} {$i < $count} {incr i} { - $r read - } - } } gen_write_load [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] [lindex $argv 4] [lindex $argv 5] [lindex $argv 6] From 0192dbf14f8827641ef38118b6b1f0ce6b88c648 Mon Sep 17 00:00:00 2001 From: "debing.sun" Date: Mon, 30 Mar 2026 17:07:00 +0800 Subject: [PATCH 4/4] Read remaining replies Co-authored-by: oranagra --- tests/helpers/gen_write_load.tcl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/helpers/gen_write_load.tcl b/tests/helpers/gen_write_load.tcl index 085ae3f8dd6..60d954e5dbf 100644 --- a/tests/helpers/gen_write_load.tcl +++ b/tests/helpers/gen_write_load.tcl @@ -53,12 +53,18 @@ proc gen_write_load {host port seconds tls {key ""} {size 0} {sleep 0}} { } if {[clock seconds]-$start_time > $seconds} { - exit 0 + break } if {$sleep ne 0} { after $sleep } } + + # Read remaining replies + for {set i 0} {$i < $count} {incr i} { + $r read + } + exit 0 } gen_write_load [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3] [lindex $argv 4] [lindex $argv 5] [lindex $argv 6]