Dear Antonio,
i see the problem: when you put the chat into the master template then every user/client will become a member of the chat. The back-channel wont be closed, the server can't detect precisely, what connection should be reaped. Sending spaces (as in your changes) is not a good idea either, since one should keep the communication transparent. Furthermore, one has to cleanup not only the stale sockets, but as well the nsv-variables keeping the per-chat context. Doing the sweep over all chat clients for every message does not scale well.
What i have done now is to re-factor the subscriber logic a little to reduce potential code duplication and to call the subscriber sweeper from the (already preexisting) chat sweeper. The chat sweeper has configurable sweepinterval. The changes are in CVS head.
For watching the open files, i would recommend munin [1], for which i have written a set of plugins [2] mostly for naviserver, some of these work for aolserer as well. The set of plugins contains as well a monitor for open files to avoid surprises, when one is running out of file-handles (see sample view [3]).
I did not have the chance yet to look at last javascript/character coding changes.
best regards
-gustaf neumann
[1] http://munin-monitoring.org/
[2] git clone git://alice.wu.ac.at/munin-plugins
[3] https://openacs.org/xowiki/file/naviserver_production_lsof-month.png
[4] http://cvs.openacs.org/changelog/OpenACS?cs=MAIN%3Agustafn%3A20130221123133