summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
authorYossi Gottlieb <yossigo@gmail.com>2022-07-03 13:34:14 +0300
committerGitHub <noreply@github.com>2022-07-03 13:34:14 +0300
commit69d5576832a02af43f2b1bdc7e94abfc92a27907 (patch)
treeb338c369c0253e9eaf6c3bc13f117b2a23261de8 /tests/support
parent2ab6767744a3b31db9cba7445ae6cc94f33b6d51 (diff)
downloadredis-69d5576832a02af43f2b1bdc7e94abfc92a27907.tar.gz
Fix TLS tests on newer tcl-tls/OpenSSL. (#10910)
Before this commit, TLS tests on Ubuntu 22.04 would fail as dropped connections result with an ECONNABORTED error thrown instead of an empty read.
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/redis.tcl41
1 files changed, 34 insertions, 7 deletions
diff --git a/tests/support/redis.tcl b/tests/support/redis.tcl
index edcc1fb48..861e8bc27 100644
--- a/tests/support/redis.tcl
+++ b/tests/support/redis.tcl
@@ -67,6 +67,33 @@ proc redis {{server 127.0.0.1} {port 6379} {defer 0} {tls 0} {tlsoptions {}} {re
interp alias {} ::redis::redisHandle$id {} ::redis::__dispatch__ $id
}
+# On recent versions of tcl-tls/OpenSSL, reading from a dropped connection
+# results with an error we need to catch and mimic the old behavior.
+proc ::redis::redis_safe_read {fd len} {
+ if {$len == -1} {
+ set err [catch {set val [read $fd]} msg]
+ } else {
+ set err [catch {set val [read $fd $len]} msg]
+ }
+ if {!$err} {
+ return $val
+ }
+ if {[string match "*connection abort*" $msg]} {
+ return {}
+ }
+ error $msg
+}
+
+proc ::redis::redis_safe_gets {fd} {
+ if {[catch {set val [gets $fd]} msg]} {
+ if {[string match "*connection abort*" $msg]} {
+ return {}
+ }
+ error $msg
+ }
+ return $val
+}
+
# This is a wrapper to the actual dispatching procedure that handles
# reconnection if needed.
proc ::redis::__dispatch__ {id method args} {
@@ -148,8 +175,8 @@ proc ::redis::__method__read {id fd} {
::redis::redis_read_reply $id $fd
}
-proc ::redis::__method__rawread {id fd len} {
- return [read $fd $len]
+proc ::redis::__method__rawread {id fd {len -1}} {
+ return [redis_safe_read $fd $len]
}
proc ::redis::__method__write {id fd buf} {
@@ -207,8 +234,8 @@ proc ::redis::redis_writenl {fd buf} {
}
proc ::redis::redis_readnl {fd len} {
- set buf [read $fd $len]
- read $fd 2 ; # discard CR LF
+ set buf [redis_safe_read $fd $len]
+ redis_safe_read $fd 2 ; # discard CR LF
return $buf
}
@@ -254,11 +281,11 @@ proc ::redis::redis_read_map {id fd} {
}
proc ::redis::redis_read_line fd {
- string trim [gets $fd]
+ string trim [redis_safe_gets $fd]
}
proc ::redis::redis_read_null fd {
- gets $fd
+ redis_safe_gets $fd
return {}
}
@@ -281,7 +308,7 @@ proc ::redis::redis_read_reply {id fd} {
}
while {1} {
- set type [read $fd 1]
+ set type [redis_safe_read $fd 1]
switch -exact -- $type {
_ {return [redis_read_null $fd]}
: -