uProxy-p2p icon indicating copy to clipboard operation
uProxy-p2p copied to clipboard

Simple SOCKS fails to start occasionally

Open mollyling opened this issue 12 years ago • 11 comments

From #388 - The simple socks server sometimes doesn't accept connections until you restart.

mollyling avatar Dec 04 '14 21:12 mollyling

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.

iislucas avatar Dec 17 '14 21:12 iislucas

I think @mollyling is best placed to figure this out, changing assignment. :)

iislucas avatar Jan 07 '15 22:01 iislucas

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

trevj avatar Jan 08 '15 15:01 trevj

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.

mollyling avatar Jan 08 '15 16:01 mollyling

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!

trevj avatar Jan 08 '15 17:01 trevj

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 listening and client connected but nothing else.
    • Make a connection to the server on port 9998 using telnet:
    • telnet will connect but the server will never receive the onConnection event.
  • Now, reload the app:
    • The JavaScript console should show server listening and client connected and NEW CONNECTION.
    • Making more connections to the server via telnet will work now, too.

Expected behaviour: the server should always receive onConnection events and you should always see NEW CONNECTION in the JavaScript console.

trevj avatar Jan 08 '15 21:01 trevj

This promises good times ahead.

mollyling avatar Jan 08 '15 21:01 mollyling

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?

trevj avatar Jan 08 '15 21:01 trevj

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.

trevj avatar Jan 08 '15 21:01 trevj

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.

trevj avatar Jan 08 '15 22:01 trevj

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.

trevj avatar Jan 21 '15 16:01 trevj