Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Internet Explorer incorrectly breaks off connection each 15 seconds, the server doesn't fulfill onClose event #33

Closed
webspec2012 opened this issue Mar 6, 2015 · 15 comments
Assignees
Labels

Comments

@webspec2012
Copy link

No description provided.

@Hywan
Copy link
Member

Hywan commented Mar 6, 2015

Excuse me, but what did you do exactly?

@Hywan Hywan added the question label Mar 6, 2015
@Hywan Hywan self-assigned this Mar 6, 2015
@webspec2012
Copy link
Author

Sample server:

date_default_timezone_set('UTC');
require_once "vendor/autoload.php";
if (!defined('HOA')) {
    die("Failed start daemon: Hoa-socket lib not found");
}

// get unique client ID
function getClientId($bucket) {
    return $bucket->getSource()->getConnection()->getCurrentNode()->getId();
}

// server run
$websocket = new Hoa\Websocket\Server(
    new Hoa\Socket\Server('tcp://0.0.0.0:3333')
);

$websocket->on('open', function ( Hoa\Core\Event\Bucket $bucket ) {

    echo 'new connection #', getClientId($bucket), "\n";

    return;
});

$websocket->on('message', function ( Hoa\Core\Event\Bucket $bucket ) {

    $data = $bucket->getData();
    echo '> message ', $data['message'], "\n";
    $bucket->getSource()->send($data['message']);
    echo '< echo', "\n";

    return;
});

$websocket->on('close', function ( Hoa\Core\Event\Bucket $bucket ) {
    echo 'connection closed #', getClientId($bucket), "\n";

    return;
});

$websocket->run();

Sample Client:
http://fulledu.ru/websocket/

<input type="text" id="input" placeholder="Message…" />
<hr />
<pre id="output"></pre>

<script>
    function mySocketServer() {
        var host   = 'ws://fulledu.ru:3333';
        var socket = null;
        var input  = document.getElementById('input');
        var output = document.getElementById('output');
        var print  = function ( message ) {

            var samp       = document.createElement('samp');
            samp.innerHTML = message + '\n';
            output.appendChild(samp);

            return;
        };

        input.addEventListener('keyup', function ( evt ) {

            if(13 === evt.keyCode) {

                var msg = input.value;

                if(!msg)
                    return;

                try {

                    socket.send(msg);
                    input.value = '';
                    input.focus();
                }
                catch ( e ) {

                    console.log(e);
                }

                return;
            }
        });

        try {

            socket = new WebSocket(host);
            socket.onopen = function ( ) {

                print('connection is opened');
                input.focus();

                return;
            };
            socket.onmessage = function ( msg ) {

                print(msg.data);

                return;
            };
            socket.onclose = function ( ) {
                print('connection is closed');

                setTimeout(function(){mySocketServer()}, 1000 * 2);

                return;
            };
        }
        catch ( e ) {
            console.log(e);
        }
    }

    mySocketServer();
</script>

Result screenshot with Internet Explorer:
http://static.fulledu.ru/example_bug.png

onClose event not work...

@Hywan
Copy link
Member

Hywan commented Mar 9, 2015

Which version of Internet Explorer are you using?

@Hywan Hywan assigned thehawk970 and unassigned Hywan Mar 9, 2015
@Hywan
Copy link
Member

Hywan commented Mar 9, 2015

I assign @camael24 on this one. He will try to reproduce.

@webspec2012
Copy link
Author

"Internet Explorer 11"

The same bug can be reproduced if connection is broken off by the third party.
For example:

  • At the client the Internet was gone
  • Connection with the client was broken off by nginx on timeout (if use nginx proxy for server)

or etc..

@Hywan
Copy link
Member

Hywan commented Mar 9, 2015

Is it the same issue you reported #31, #32 and #30?

@webspec2012
Copy link
Author

Possibly it is other mistakes, for certain I can't tell.

@thehawk970
Copy link

I try to reproduce tomorrow :)

@thehawk970
Copy link

I confirm the "bug", i reproduce it on IE11

@webspec2012
Copy link
Author

It is required that the event of onClose would work anyway if the client was disconnected from the server.

@Hywan
Copy link
Member

Hywan commented Mar 19, 2015

It's going to be difficult to debug, I don't have Windows. Any idea how could I do that?

@thehawk970
Copy link

With an VM ? and an demo key

@thehawk970
Copy link

@Hywan
Copy link
Member

Hywan commented Mar 19, 2015

Perfect! Thanks.

@Hywan
Copy link
Member

Hywan commented Apr 13, 2015

Here is what need to be considered.

IE sends an unsollicited PONG frame. The RFC6455 says:

A Pong frame MAY be sent unsolicited. This serves as a
unidirectional heartbeat. A response to an unsolicited Pong frame is
not expected.

Several implementations out there (Play, Spring, Go etc.) encountered this issue because receiving an unsollicited PONG was not expected and was creating a bug. In Hoa\Websocket, this is not the case because we handle it as required by the RFC. IE has the fin parameter set to 1, not 0, so this is a valid frame and we don't respond to it.

Since we don't respond, IE sends a random frame that is not a valid one. And yes, random, I don't receive the same frame twice.
After some searches, it seems that this is a known bug in IE10 (not 11). To fix that, we may return a PING. This is what I did, but it does not fix anything. Maybe on IE10, but not on IE11.

Because the bug is still opened on IE10, we can assume this is still present in IE11.

I close this issue because I can't do anything to avoid that… The connection is closed by the server because of the malformed/invalid message we receive after the PONG. IE does not fire the CloseEvent properly despites the server sends a valid close frame!

Sorry for that. If you find a server that handles IE11 properly, I would be glad to know them and look inside the code to see what workaround they found.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants