Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssl only: Error reading data from socket: Not connected #80

Closed
dumshi opened this issue Jan 17, 2016 · 7 comments
Closed

ssl only: Error reading data from socket: Not connected #80

dumshi opened this issue Jan 17, 2016 · 7 comments

Comments

@dumshi
Copy link

dumshi commented Jan 17, 2016

Chrome gives this error:
WebSocket connection to 'wss://server.somewhere:8000/echo' failed: WebSocket opening handshake was canceled

I get this error when testing server_ssl.php in cli:

root@m1048:/var/www/html/Wrench-master/examples# php -q server_ssl.php
info: Server initialized
info: Wrench\ConnectionManager: Wrench\Connection: 80.xxx.xxx.xxx:61207 (38bcbf66a45efe6f76292087dacb1b3fdbb35262dcce1d98c5473f0d4ba62794e0126f634cc264c519727021553be8b420fcb795f3f53eb6aa82cc7d7725a7c2): Connected
notice: Wrench\ConnectionManager: Client connection closed: exception 'Wrench\Exception\CloseException' with message 'Error reading data from socket: Not connected' in /var/www/html/Wrench-master/lib/Wrench/Connection.php:396
Stack trace:
#0 /var/www/html/Wrench-master/lib/Wrench/ConnectionManager.php(243): Wrench\Connection->process()
#1 /var/www/html/Wrench-master/lib/Wrench/ConnectionManager.php(168): Wrench\ConnectionManager->processClientSocket(Resource id #32)
#2 /var/www/html/Wrench-master/lib/Wrench/Server.php(198): Wrench\ConnectionManager->selectAndProcess()
#3 /var/www/html/Wrench-master/examples/server_ssl.php(54): Wrench\Server->run()
#4 {main}

warning: Wrench\ConnectionManager: Wrench\Connection: 80.xxx.xxx.xxx:61207 (38bcbf66a45efe6f76292087dacb1b3fdbb35262dcce1d98c5473f0d4ba62794e0126f634cc264c519727021553be8b420fcb795f3f53eb6aa82cc7d7725a7c2): Unable to send close message

This does not happen in normal plain "server.php" test, only in ssl.

@dumshi
Copy link
Author

dumshi commented Jan 18, 2016

Ok,
After few testing and reading. I also went to https://server.somewhere:8000 port and accepted the self-signed cert.
I have to leave that window OPEN for the next window with https://server.somewhere/ with wss:// to work.

Also started to notice weird things when I send a chat msg.

WebSocket - status 0
Welcome - status 1
Sent: asdf
Sent: asdf
Received: asdf
Sent: asdfasdf
Received: asdf
Sent: a
Received: asdfasdf
Sent: a
Received: a
Sent: a
Received: a
Sent: asdf
Received: a
Sent: a
Received: asdf
Sent: asdf
Received: a

Notice how the first msg was never "sent" (hence did not receive immediately).
Asap, i sent the 2nd msg, the first msg bounced back (assuming when i sent the 2nd msg, the first was went to server).
Is there a Queue system of some kind in SSL mode ??

What is going on?

I had same problem with my other project, and so I decided to download a fresh new Wrench copy.
And I am seeing similar things.

Please someone explain.

Help!!!

@dumshi
Copy link
Author

dumshi commented Jan 18, 2016

I am using helper for the workaround.
If anyone knows how to fix this, please let me know.
Thanks in advance.

Workaround:
*WebSocket helpers
* Checks websocket state before sending.
*/
this.waitForConnection = function (callback, interval) {
if (websocket.readyState === 1) {
callback();
} else {
var that = this;
setTimeout(function () {
that.waitForConnection(callback);
}, interval);
}
};
function send(message, callback) {
this.waitForConnection(function () {

        websocket.send(message);
            websocket.send(""); //send empty msg after your real msg.

        if (typeof callback !== 'undefined') {
          callback();
        }
    }, 1000);
};

@Alarmfifa
Copy link
Contributor

Hi!
I'm not sure that this problem is related to server hang, but could you check this fix

@emadruida
Copy link
Contributor

It looks like Issue #61 to me. See if this can help you.

@dumshi
Copy link
Author

dumshi commented Jan 18, 2016

@Alarmfifa It did not look like anything to do with Large Messages, as I was only send "asdf". But thank you for your reply.

@emadruida Your fix did the trick.

Thank you both for quick reply.

@Alarmfifa
Copy link
Contributor

@Alarmfifa It did not look like anything to do with Large Messages, as I was only send "asdf". But thank you for your reply.

"Large message" isn't only for message data. It is about full http message with it's header (cookies for example).
I debugged with small message, but with a big header in one browser. So, my problem is a bit difficult for reproducing.

dominics added a commit that referenced this issue Feb 11, 2017
Proposed fix for issues #61 and #80
@dominics
Copy link
Member

dominics commented Feb 12, 2017

The fix mentioned by @emadruida has been merged into v2.0.8 (and v3.0.x-dev) (9dd8175) - let me know if that fixes things

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

No branches or pull requests

4 participants