Commit de4d78d7 authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by Oran Agra
Browse files

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.

(cherry picked from commit 69d55768)
parent e5e642aa
...@@ -66,6 +66,33 @@ proc redis {{server 127.0.0.1} {port 6379} {defer 0} {tls 0} {tlsoptions {}} {re ...@@ -66,6 +66,33 @@ proc redis {{server 127.0.0.1} {port 6379} {defer 0} {tls 0} {tlsoptions {}} {re
interp alias {} ::redis::redisHandle$id {} ::redis::__dispatch__ $id 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 # This is a wrapper to the actual dispatching procedure that handles
# reconnection if needed. # reconnection if needed.
proc ::redis::__dispatch__ {id method args} { proc ::redis::__dispatch__ {id method args} {
...@@ -192,8 +219,8 @@ proc ::redis::redis_writenl {fd buf} { ...@@ -192,8 +219,8 @@ proc ::redis::redis_writenl {fd buf} {
} }
proc ::redis::redis_readnl {fd len} { proc ::redis::redis_readnl {fd len} {
set buf [read $fd $len] set buf [redis_safe_read $fd $len]
read $fd 2 ; # discard CR LF redis_safe_read $fd 2 ; # discard CR LF
return $buf return $buf
} }
...@@ -239,11 +266,11 @@ proc ::redis::redis_read_map {id fd} { ...@@ -239,11 +266,11 @@ proc ::redis::redis_read_map {id fd} {
} }
proc ::redis::redis_read_line fd { proc ::redis::redis_read_line fd {
string trim [gets $fd] string trim [redis_safe_gets $fd]
} }
proc ::redis::redis_read_null fd { proc ::redis::redis_read_null fd {
gets $fd redis_safe_gets $fd
return {} return {}
} }
...@@ -266,7 +293,7 @@ proc ::redis::redis_read_reply {id fd} { ...@@ -266,7 +293,7 @@ proc ::redis::redis_read_reply {id fd} {
} }
while {1} { while {1} {
set type [read $fd 1] set type [redis_safe_read $fd 1]
switch -exact -- $type { switch -exact -- $type {
_ {return [redis_read_null $fd]} _ {return [redis_read_null $fd]}
: - : -
......
...@@ -111,7 +111,7 @@ start_server {tags {"obuf-limits"}} { ...@@ -111,7 +111,7 @@ start_server {tags {"obuf-limits"}} {
# Read nothing # Read nothing
set fd [$rd channel] set fd [$rd channel]
assert_equal {} [read $fd] assert_equal {} [$rd rawread]
} }
# Note: This test assumes that what's written with one write, will be read by redis in one read. # Note: This test assumes that what's written with one write, will be read by redis in one read.
...@@ -151,8 +151,7 @@ start_server {tags {"obuf-limits"}} { ...@@ -151,8 +151,7 @@ start_server {tags {"obuf-limits"}} {
assert_equal "PONG" [r ping] assert_equal "PONG" [r ping]
set clients [r client list] set clients [r client list]
assert_no_match "*name=multicommands*" $clients assert_no_match "*name=multicommands*" $clients
set fd [$rd2 channel] assert_equal {} [$rd2 rawread]
assert_equal {} [read $fd]
} }
test {Execute transactions completely even if client output buffer limit is enforced} { test {Execute transactions completely even if client output buffer limit is enforced} {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment