SWI-Prolog / packages-pengines

Pengines: Prolog engines
11 stars 13 forks source link

bug in pengines.abort #8

Closed torbjornlager closed 10 years ago

torbjornlager commented 10 years ago

If you click Start and then Abort, the following example produces an Internal server error "message_queue `'$message_queue'(247)' does not exist". Can be seen in e.g. Firebug:

http://pengines.swi-prolog.org/apps/scratchpad/index.html#b0b098b8-0fe4-11e4-be3e-00163e8bf66a.html

And if the link will become invalid:

<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script type="text/javascript" src="/vendor/jquery/jquery-2.0.3.min.js"></script>
        <script type="text/javascript" src="/pengine/pengines.js"></script>
        <script type="text/x-prolog">

            main :-
                pengine_output('Hello world!'),
                sleep(1),
                pengine_output('Goodbye world!'),
                sleep(1),
                main.

        </script>
        <script type="text/javascript">
            var pengine;
            function start() {
                pengine = new Pengine({
                    ask: 'main',
                    onoutput: handleOutput,
                    onabort: handleAbort
                });
            }
            function handleOutput() {
                $("#msg").html("<h1>" + this.data + "</h1>");
            }
            function handleAbort() {
                $("#err").html("<h4>Aborted</h4>");
            }
        </script>
    </head>
    <body>
        <center style="margin-top:200px;">
            <div id="msg"></div>
            <button onclick="start()">Start</button>
            <button onclick="pengine.abort()">Abort</button>
            <div id="err"></div>
        </center>
    </body>
</html>
JanWielemaker commented 10 years ago

This is because abort() is issued while a pull_response is in progress. This implies that the reply to the abort is handed to the pull_response, leaving the abort HTTP handler with a non-existing pengine. I've fixed this by responding with a died event and updated pengines.js to ignore the died if it is a response to an abort().