On Tue, Dec 21, 2010 at 4:51 PM, Steve Vinoski <vinoski@ieee.org> wrote:
On Tue, Dec 21, 2010 at 12:07 PM, Michal D. <michal.dobrogost@gmail.com> wrote:
> Hi,
> I'm trying to write a fairly simple AJAX multiplayer game in Yaws.  I spawn
> a seperate process to handle the server state across all clients.  There are
> two .yaws files, both called from JavaScript by xml http request objects via
> GET.
> submit.yaws - query string holds a an action performed by the player
> (affects state server, client ignores any response).
> request.yaws - subscribes to state server modification notifications, then
> wais for a message from the state server with the new state.
> The problem is that once submit.yaws is accessed a process dies (different
> pid from processes handling submit.yaws or request.yaws). After this, the
> request.yaws seems to hang and no new updates come in. The process that dies
> shows up with the following message:
> =ERROR REPORT==== 21-Dec-2010::12:03:56 ===
> Yaws process died: {function_clause,[{yaws_server,binary_size,[0,<0.71.0>]},
>                                      {yaws_server,binary_size,2},
>                                      {yaws_server,deliver_accumulated,5},
>                                      {yaws_server,finish_up_dyn_file,2},
>                                      {yaws_server,aloop,3},
>                                      {yaws_server,acceptor0,2},
>                                      {proc_lib,init_p_do_apply,3}]}
> Any hints on what's going on?

I'm guessing you're giving Yaws some bad values to be returned as part
of the response body from your .yaws code. Can you either post your
.yaws code or send me a copy offline?


Hi Steve,

Thanks for taking an interest in my problem.   I created a toy version that will hopefully be easier to debug but it doesn't have exactly the same problem.  Same: sometimes 'reset' will hang the counter.  Different: real page always seems to hang, toy does not crash any processes.  Hopefully it will give you an idea of what's going on though.  I'll send the real code if still necessary.

Sorry for the longish message, this is as much as I could get it down.

=== yaws/request.yaws =========================

out(A) ->
    io:put_chars("request.yaws hello\n\n"),

    % Start the game server if it's not running yet.

    % Send the request.
    global:send(stateServer, {request, self()}),
    receive Result -> {html, Result} end.

=== yaws/submit.yaws =========================

out(A) ->
    io:put_chars("submit.yaws hello\n\n"),

    % Start the game server if it's not running yet.

    % Send submit.
    global:send(stateServer, submit),
    {html, ""}.

=== ebin/ebin.erl ==============================
-export([state_server/2, start_server/0]).

term_to_str(T) -> lists:flatten(io_lib:format("~p", [T])).

% Start the game server if it's not running yet.
start_server() ->
    case global:whereis_name(stateServer) of
        undefined ->
                Pid = spawn(ebin, state_server, [0, []]),
                global:register_name(stateServer, Pid),
                erlang:start_timer(1000, Pid, {});

        _ -> {}

state_server(Count, Requests) ->
        {request, Pid} ->
            state_server(Count, [Pid|Requests]);

        submit ->
            lists:map(fun(Pid) -> Pid ! term_to_str(Count) end, Requests),
            state_server(0, []);

        {timeout, _, _} ->
            erlang:start_timer(1000, self(), {}),
            lists:map(fun(Pid) -> Pid ! term_to_str(Count) end, Requests),
            state_server(Count+1, []);

        X ->
            io:put_chars("server got unkown message:"),
=== index.html =====================================
    <script type="text/javascript">

        function NewXmlHttpRequest() {
            var xmlhttp;

            // code for IE7+, Firefox, Chrome, Opera, Safari
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
            // code for IE6, IE5
            else {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            xmlhttp.isReady = function() {
                // xmlhttp.status is defined once xmlhttp.readyState >= 2
                return this.readyState === 4 && this.status === 200;
            return xmlhttp;   

        function request() {
            xmlhttp = NewXmlHttpRequest();
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.isReady()) {
                    document.getElementById("counter").innerHTML =

            // Send request off to server
            xmlhttp.open("GET", "yaws/request.yaws", true);

        function submit() {
            // Callback
            xmlhttp = NewXmlHttpRequest();
            xmlhttp.onreadystatechange = function() {}
            // Send request off to server
            xmlhttp.open("GET","yaws/submit.yaws", true);

        <div id="counter">?</div>
        <input type="button" value="Reset" onclick="submit()">
        <div id="debug">_debug_</div>
        <script type="text/javascript">request()</script>
=== yaws.conf ==============================
ebin_dir = "ebin/"

<server localhost>
    port = 8080
    listen =
    docroot = /home/mkd/www/prewix_bug