Dear Claudio,
Probably you are facing different issues. Let's first look at "connection socket is detached", what it means, why this error makes sense, and how to avoid it.
Look at the following script:
if {[ns_queryget stop 0]} {
ns_return 200 text/plain "break out"
}
set msg "end of script"
ns_return 200 text/plain $msg
When test-me.tcl is called from the browser without parameter, it returns a page with "end of script". When it is called with the query parameter stop=1, it enters the if branch and returns "break out" to the client. The important thing is after the ns_return
: in both AOLserver and NaviServer, the script continues to execute and reaches (after probably some more commands) the 2nd ns_return
. However, this 2nd ns_return
can't work, since the script has already replied to "break out" to the user and cannot reply on the same connection once again. In general, the continuation after the command can lead to situations and strange error messages which are hard to debug.
Therefore, NaviServer raises since version 4.99.16 (released 2017-12-29) an exception in such situations, telling the user that this script can't work as programmed.
The continuation after ns_return
and similar commands is probably not expected and not wanted by the developer. The right thing to address this issue is to add a return
(in an executing script) or a ad_script_abort
in library functions.
if {[ns_queryget stop 0]} {
ns_return 200 text/plain "break out"
return ;
}
set msg "end of script"
ns_return 200 text/plain $msg
In all the maintained packages (~100) in the public OpenACS repository, such issues has been fixed.
It is possible to avoid raising an exception in such cases by setting in the NaviServer configuration file in section ns/params
the parameter rejectalreadyclosedconn
to false (see e.g. in [2]). This is not recommended. There is as well a page in the wiki [3] addressing this situation.
Hope this helps
-g
[1] NaviServer 4.99.16
[2] OpenACS configuration file
[3] connection-already-closed