Simple SOCKS fails to start occasionally
From #388 - The simple socks server sometimes doesn't accept connections until you restart.
Would be good to know how frequently it happens: @klazizpro can you chat with @trevj and figure out how often this happens? Maybe run 50 times, and see how often this happens. Ideally on the new windows machine.
I think @mollyling is best placed to figure this out, changing assignment. :)
Just to point out that I've been working on some integration tests for uproxy-networking and am seeing what looks like weird TCP socket behaviour on initial extension load (subsequent loads work fine). Might be related: https://github.com/uProxy/uproxy-networking/pull/178
OK, tracked down a file-length problem to a likely mime-type issue in wup (e.g., not our problem). Currently tracking down tcp provider's accept() issues.
I spent the morning looking into what I think is the accept issue as part of getting the TCP integration test to work so can take this. Sorry, didn't think the two would turn out to be related!
Super weird. This looks like a Chrome bug affecting version 41, at least, but apparently not 39. I don't see this behaviour at all in Firefox.
Here's some code:
var s = freedom['core.tcpsocket']();
s.on('onConnection', (acceptValue:freedom_TcpSocket.ConnectInfo) : void => {
log.info('NEW CONNECTION');
});
s.listen('127.0.0.1', 9998).then(() => {
log.info('server listening');
var c = freedom['core.tcpsocket']();
c.connect('127.0.0.1', 9998).then(
() => { log.info('client connected'); },
(e:Error) => { log.error('client could not connect: ' + e.message); });
}, (e:Error) => { log.error('server failed to listen: ' + e.message); });
To reproduce:
- Start Chrome from fresh.
- Load an app containing the above code:
- The JavaScript console should show
server listeningandclient connectedbut nothing else. - Make a connection to the server on port 9998 using telnet:
- telnet will connect but the server will never receive the
onConnectionevent.
- The JavaScript console should show
- Now, reload the app:
- The JavaScript console should show
server listeningandclient connectedandNEW CONNECTION. - Making more connections to the server via telnet will work now, too.
- The JavaScript console should show
Expected behaviour: the server should always receive onConnection events and you should always see NEW CONNECTION in the JavaScript console.
This promises good times ahead.
So, if I take Freedom out of the mix then I do receive the connections, in Chrome 39 and 41.
{
"manifest_version": 2,
"name": "accept",
"description": "accept issue reproduce case",
"version": "0.1",
"app": {
"background": {
"scripts": [
"background.js"
]
}
},
"permissions": [],
"sockets": {
"tcp": {
"connect" : ""
},
"tcpServer": {
"listen": ""
}
}
}
chrome.sockets.tcpServer.create({}, function(createInfo) {
console.log('server socket created: ' + JSON.stringify(createInfo));
chrome.sockets.tcpServer.listen(createInfo.socketId, '127.0.0.1', 9998, function(resultCode) {
if (resultCode < 0) {
console.log('could not create server socket: ' + chrome.runtime.lastError.message);
return;
}
console.log('server listening');
chrome.sockets.tcpServer.onAccept.addListener(function(info) {
console.log('NEW CONNECTION: ' + JSON.stringify(info));
});
});
});
Output, if I connect via telnet:
server socket created: {"socketId":1}
server listening
NEW CONNECTION: {"clientSocketId":1,"socketId":1}
Isn't it weird that the socket IDs are identical?
Oh wait maybe the socket ID namespace is distinct for server and client sockets.
Anyway, seems like something somewhere changed in Chrome 41 that is mucking up how Freedom interacts with sockets.
At this point I suspect the issue occurs when the server socket and client socket have the same ID. It doesn't always happen (right now I can't reproduce the issue using the above steps at all...very annoying!). I'll have to look at the TCP provider in Freedom a little more.
While I'm not 100% convinced we don't still have some strange weirdness going on with TCP sockets in Chrome, this specific issue has been addressed in freedom-for-chrome 0.4.11.