Forum OpenACS Q&A: Re: connection socket is detached

Posted by Gustaf Neumann on
Glad, that everything is fine with your script. A few comments to this snippet

ns_writer submitfile $path
# here it seems the connection gets closed

It is rather unlikely that at the place of your comment, the connection is closed, but it is detached. What does this mean: the command "ns_writer submitfile" passes the control to a writer thread (assuming you have writer threads defined), which will asynchronously deliver the file content of this connection to the client. It is unlikely that at the time when you execute the next command in this script, the delivery is already finished. The duration of the delivery depends on the client and its connection: when the client is e.g. connected via smartphone over a cellular network, this will take longer than a user connected from the same LAN.

# file delete $some_other_path #is ok
# ns_unlink $some_other_path #produces the error message reported before

The deprecated command "ns_unlink" has three conditions [1], when it raises an exception (wrong number of arguments, trying to delete a directory, trying to delete a non-existing file) - all of these look reasonable to me, but probably, one of these fired in your case.... and for reason not visible from your report "file delete" does not raise these (note, that "ns_unlink" executes as last command "file delete" as well).

When the command raises an exception in a connection thread in detached state, "rp_handler" will catch the exception, and it tries to deliver the error message on the detached connection. This can't work, since the writer thread is at the same time busy to deliver the file on this connection.

Therefore, OpenACS got a change ~16 months ago to avoid the error message you have reported via change [2]. Probably, you are using some older version.