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

Failed to create data channel after visited a few pages (each contains many connections)

Open quantsword opened this issue 12 years ago • 15 comments

Running latest socks sample from uproxy-networking socks-server/samples/simple-socks-chromapp

Setting firefox to use sock5 server at localhost:9999

Visited some pages from cnn.com Visited some pages from www.epochtimes.com

Began to see error on console:

Uncaught NotSupportedError: Failed to execute 'createDataChannel' on 'RTCPeerConnection': RTCDataChannel is not supported

No further page can be visited.

Running my old script for more than 20 minutes, with over 10k channel established and closed, it seems working fine.

quantsword avatar Sep 19 '14 21:09 quantsword

We put a hack in to uproxy-networking to manually control the channel id; now the fixes are in Chrome (from version 38 onwards), we should remove our hack and let the underlying WebRTC choose channel ids and then it will re-use them and we wont his the problem. @trevj you know what I'm talking about :)

iislucas avatar Sep 21 '14 13:09 iislucas

I added some log code today, and found with latest chrome (v39 beta and canary), uproxy can open 1024 channels, but not more. (I don't understand why in my ping/pong test code, I could create more data channel.) I did checked the close of those channel, it seems fine.

quantsword avatar Sep 24 '14 01:09 quantsword

One mistake in previous comment and some new info. The previous test is on v39 beta channel. After I switched to canary, webrtc basically stopped working. It seems canary is very broken.

quantsword avatar Sep 24 '14 01:09 quantsword

So, I spent some time on this today. I ended up writing a ping pong-type app to test. I suspect it's similar to @quantsword's:

  • peer A opens a data channel, sends some data to peer B
  • peer B receives the data and closes the data channel
  • peer A detects that the data channel has closed and opens a new data channel
  • (repeat)

I have varying degrees of success in each of Chrome 37, Chrome 39, and Firefox 34:

  • Chrome 37: cycle repeats 1024 times before failures occur
  • Chrome 39: cycle repeats 3-4 times before events are no longer emitted (if I keep channels open and just loop, creating data channels, then I can open 1024 channels before failures occur)
  • Firefox 34: same behaviour as Chrome 39 (if I keep channels open and just loop, creating data channels, then I can open 16 data channels before Firefox crashes)

So, it seems we do have issues coming up.

The only thing that works right now in all browsers is to keep a small number of channels open. Obviously, it's better for everybody if channels can be re-used -- but I suspect we could make the SOCKS server work with this limitation.........depends how easy a fix channel re-use is, I guess.

trevj avatar Sep 24 '14 23:09 trevj

What is the failure in Chrome?

Are you running A and B in the same browser instance? Which part fails, A or B?

On Wed, Sep 24, 2014 at 7:12 PM, trevj [email protected] wrote:

So, I spent some time on this today. I ended up writing a ping pong-type app to test. I suspect it's similar to @quantsword https://github.com/quantsword's:

  • peer A opens a data channel, sends some data to peer B
  • peer B receives the data and closes the data channel
  • peer A detects that the data channel has closed and opens a new data channel
  • (repeat)

I have varying degrees of success in each of Chrome 37, Chrome 39, and Firefox 34.

  • Chrome 37: cycle repeats 1024 times before failures occur
  • Chrome 39: cycle repeats 3-4 times, varying slightly each time (if I keep channels open and just loop, creating data channels, then I can open 1024 channels before failures occur)
  • Firefox 34: same behaviour as Chrome 39 (if I keep channels open and just loop, creating data channels, then I can open 16 data channels before Firefox crashes)

So, it seems we do have issues coming up.

The only thing that works right now in all browsers is to keep a small number of channels open. Obviously, it's better for everybody if channels can be re-used -- but I suspect we could make the SOCKS server work with this limitation.........depends how easy a fix channel re-use is, I guess.

— Reply to this email directly or view it on GitHub https://github.com/uProxy/uproxy/issues/388#issuecomment-56753233.

salomegeo avatar Sep 24 '14 23:09 salomegeo

The failure is that createDataChannel raises an exception.

I'm running A and B in the same browser instance.

A tries to create the data channel, so it's A that fails.

When events are no longer emitted, it gets hard to say which part fails.

trevj avatar Sep 24 '14 23:09 trevj

There seems to be an additional problem concerning sockets. Shortly after requesting a few complex pages (so perhaps ~200 separate requests) I start seeing this error:

Unchecked runtime.lastError while running sockets.tcp.send: net::ERR_SOCKET_NOT_CONNECTED
    at Socket_chrome.write (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:4800:46)
    at null.<anonymous> (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:1392:109)
    at fdom.port.Provider.onMessage (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:1269:51)
    at fdom.Hub.onMessage (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:255:37)
    at Object.<anonymous> (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:1905:112)
    at fdom.port.Module.emitMessage (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:948:40)
    at Object.<anonymous> (chrome-extension://blphoeojoaboiakpncibkkekmmijdgll/lib/freedom/freedom-for-chrome-for-uproxy.js:1907:84) 

Investigating...this seems separate to the WebRTC issues. Doesn't happen all the time but does seem to be a serious issue.

trevj avatar Sep 25 '14 14:09 trevj

So, we also have problems with our TCP sockets. I found an issue which I've reopened: https://github.com/freedomjs/freedom-for-chrome/issues/30

trevj avatar Sep 26 '14 15:09 trevj

For chrome, it doesn't reuse the channel IDs it passes to SCTP. There are only (in the current configuration) 1024 of them, so they get depleted. I'm testing a patch to chrome now.

mollyling avatar Sep 29 '14 14:09 mollyling

@Lally. Can you make sure we have a a text and an issue to fix this in Chrome. I was pretty sure that Jiayang fixed it already and that id are now reused. :/

On Mon, Sep 29, 2014 at 10:48 AM, Molly Ling [email protected] wrote:

For chrome, it doesn't reuse the channel IDs it passes to SCTP. There are only (in the current configuration) 1024 of them, so they get depleted. I'm testing a patch to chrome now.

— Reply to this email directly or view it on GitHub https://github.com/uProxy/uproxy/issues/388#issuecomment-57171924.

Lucas Dixon | Google Ideas

iislucas avatar Oct 01 '14 03:10 iislucas

the benchmark tests this pretty thoroughly, and I'm working on the fix for the two channel issues:

  1. Channel SSIDs aren't reused
  2. We don't grow the number of channels past 1024, when needed.

mollyling avatar Oct 01 '14 18:10 mollyling

Ok, first: it's been fixed: image

This also required fixing the same bug that required that options.id be specified in createDataChannel: without the SSL role being established, the SID allocation would fail.

Also, webkit's implementation of createDataChannel (https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/modules/mediastream/RTCPeerConnection.cpp&rcl=1412920526&l=545) coerces 'id' into an unsigned short. So far, this looks safe, but doesn't let us pass -1 into options.id. Instead, it has to be deleted.

I'll have to clean & split up the changes a bit, but it should be short order to get them all in.

mollyling avatar Oct 11 '14 21:10 mollyling

Fantastic news!

trevj avatar Oct 13 '14 14:10 trevj

So, lots of progress:

  • unit tests for SocksToRtc and RtcToNet session lifecycle (and some refactoring which gives us more confidence in the code)
  • remove the datachannel ID workaround which allows us benefit for the fix for >1024 datachannels limit
  • fixes to core.tcpsocket closures
  • reducing logging made a huge difference to the TCP echo server stress test and we've reduced the SOCKS server logging a lot

I'm now able to browse with the SOCKS server at a reasonable speed for many minutes. That's just eyeballing behaviour, of course, but I would consider closing this issue and opening more fine-grained issues in lieu (e.g. Simple SOCKS still fails to boot occasionally...not sure why, although the new integration test for the TCP wrapper may help us figure out why).

trevj avatar Nov 19 '14 20:11 trevj

Created #628 for that issue, closing htis.

mollyling avatar Dec 04 '14 21:12 mollyling