From e7e6818c81278aafe4035e9dac60958e6e72bbc1 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Tue, 26 Nov 2024 21:45:20 -0500 Subject: [PATCH] maybe workaround db locking? --- src/ws.tcl | 98 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/src/ws.tcl b/src/ws.tcl index 0b36b97..c9d94fc 100644 --- a/src/ws.tcl +++ b/src/ws.tcl @@ -220,59 +220,63 @@ namespace eval ::ws::c { [set callback($sock)] $sock close [dict get $frame data] } - if {[catch { - switch -- [dict get $frame opcode] { - 0 { - if {[set mode($sock)] ni {1 2}} { - ${log}::error "Got a continuation frame with no starting frame on $sock! Closing!" + set madeit 0 + for {set i 1} {$i <= 3 && !$madeit} {incr i} { + if {[catch { + switch -- [dict get $frame opcode] { + 0 { + if {[set mode($sock)] ni {1 2}} { + ${log}::error "Got a continuation frame with no starting frame on $sock! Closing!" + close $sock + [set callback($sock)] $sock close [set frag($sock)] + } + append frags($sock) [dict get $frame data] + if {[dict get $frame fin]} { + set frags($sock) {} + } + } + 1 { + if {[dict get $frame fin]} { + set mode($sock) {} + set frag($sock) {} + [set callback($sock)] $sock text [dict get $frame data] + } else { + set mode($sock) text + set frag($sock) [dict get $frame data] + } + } + 2 { + if {[dict get $frame fin]} { + set mode($sock) {} + set frag($sock) {} + [set callback($sock)] $sock binary [dict get $frame data] + } else { + set mode($sock) binary + set frag($sock) [dict get $frame data] + } + } + + 8 { close $sock - [set callback($sock)] $sock close [set frag($sock)] + [set callback($sock)] $sock close [dict get $frame data] } - append frags($sock) [dict get $frame data] - if {[dict get $frame fin]} { - set frags($sock) {} + 9 { + ::ws::send_frame 0 10 [dict get $frame data] [dict get $frame len] 1 } - } - 1 { - if {[dict get $frame fin]} { - set mode($sock) {} - set frag($sock) {} - [set callback($sock)] $sock text [dict get $frame data] - } else { - set mode($sock) text - set frag($sock) [dict get $frame data] + 10 { + # TODO: kill connection on missed ping? but jetstream doesn't send any it looks like } - } - 2 { - if {[dict get $frame fin]} { - set mode($sock) {} - set frag($sock) {} - [set callback($sock)] $sock binary [dict get $frame data] - } else { - set mode($sock) binary - set frag($sock) [dict get $frame data] + default { + ${log}::error "Unknown opcode [dict get $frame opcode] on $sock! Closing!" + close $sock + [set callback($sock)] $sock close [dict get $frame data] } } - - 8 { - close $sock - [set callback($sock)] $sock close [dict get $frame data] - } - 9 { - ::ws::send_frame 0 10 [dict get $frame data] [dict get $frame len] 1 - } - 10 { - # TODO: kill connection on missed ping? but jetstream doesn't send any it looks like - } - default { - ${log}::error "Unknown opcode [dict get $frame opcode] on $sock! Closing!" - close $sock - [set callback($sock)] $sock close [dict get $frame data] - } + set madeit 1 + } result options]} { + ${log}::error "error in websocket callback for ${sock} (attempt $i): $result" + ${log}::error "options: $options" } - } result options]} { - ${log}::error "error in websocket callback for ${sock}: $result" - ${log}::error "options: $options" - } + }; # end for } } -- 2.45.2