Forum OpenACS Q&A: Re: How to correctly configure the reverse proxy.

Collapse
Posted by Tony Kirkham on

I have found a solution that I would like some feedback on. I am now able to upload files > 2.5 MB through the revproxy. I have not tried much bigger than that yet, but all I try are now working.

With the 4.99.20 NaviServer I also obtained and installed the 0.14 version of the revproxy and then after some more analysis of our docker environment, I decided that perhaps the problem was now a bit higher up than I had thought and I looked closer at the the revproxy tcl calls themselves. The following are the modifications I have made to the proc upstream that fixes my problem.

diff --git a/revproxy-procs.tcl b/revproxy-procs.tcl
index 4e12711..0ace547 100644
--- a/revproxy-procs.tcl
+++ b/revproxy-procs.tcl
@@ -135,7 +135,21 @@ namespace eval ::revproxy {
                     while {$i < $length} {
                         log notice "upstream: send max $chunk bytes from string to $backendChan " \
                             "(length $contentLength)"
-                        ns_connchan write $backendChan [string range $data $i $j]
+                        set wrote [ns_connchan write $backendChan [string range $data $i $j]]
+
+                        set remain [expr {(($j+1 < $length ? $j+1 : $length) - $i) - $wrote}]
+                        set ti $i
+                        set tries 3
+                        while {$remain && $tries} {
+                            after 100; # I hate solving race conditions with a race condition - ACK 2021-05-05
+                            set ti [expr {$ti + $wrote}]
+                            log notice "upstream: - try the rest - send from $ti to $j from string to $backendChan " \
+                                "(length $contentLength)"
+                            set wrote [ns_connchan write $backendChan [string range $data $ti $j]]
+
+                            incr remain -$wrote
+                            incr tries -1
+                        }
                         incr i $chunk
                         incr j $chunk
                     }

I started to think that the "resource temporarily unavailable" may be due to an inability of the system (Node) to handle how fast the data was being sent to it. These modifications give it a breather that seems to work.

One problem with this solution is that I do not know how to access any status of the connection write so I have relied on 3 retries of a call to after, which I feel is just a bigger Band-Aid. I also still see in the logs the message "resource temporarily unavailable" on every write, even though the writes complete successfully.

Is there a way outside of ns_connchan to reset that status? Does this look like an appropriate solution or is there a better one?

Thanks,

-Tony