mozilla / libdweb

Extension containing an experimental libdweb APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TCPSocket support for Firefox 67+

sammacbeth opened this issue ยท comments

It seems the TCPSocket tests are failing on the current Firefox Developer Edition (67) and Nightly (68). The same tests can be run fine on Firefox 65.

Testing with tape-ext (on nightly) I get see the following failure:

ok 22 should be equal 8090 8090
ok 23 should be equal false false
ok 24 should be equal 0 0
ok 25 should be truthy true
ok 26 should be truthy true
ok 27 socket.write is function true
ok 28 socket.read is function true
ok 29 socket.suspend is a function true
ok 30 socket.resume is a function true
JavaScript error: resource://gre/modules/ExtensionUtils.jsm, line 0: Error: NetworkError: Network
ok 31 socket.close is a function true
JavaScript error: resource://gre/modules/ExtensionUtils.jsm, line 48: Error: Socket is not open
ok 32 socket.closeImmediately is a function true
not ok 33 server received message  Hello TCP

Would appreciate some guidance on how to further debug this.

I did some digging. It appears that sending a message from socket causes and error & it's closure. I also found out that using higher level APIs: TCPSocket & TCPServerSocket seems to work fine:

server = new TCPServerSocket(7770, {binaryType:"arraybuffer"})
server.connections = []

server.onconnect = connection => {
  server.connections.push(connection)
}

client = new TCPSocket('127.0.0.1', 7770, {binaryType: "arraybuffer"})

client.data = []
client.ondata = event => {
  client.data.push(event.data)
}

// wait

connection = server.connections.shift().socket
connection.data = []
connection.ondata = (event) => {
  connection.data.push(event.data)
}

// wait
encoder = new TextEncoder()
client.send(encoder.encode('ping').buffer)


// wait

connection.send(encoder.encode('pong').buffer)

// wait

decoder = new TextDecoder()
decoder.decode(new Uint8Array(connection.data.shift()))
decoder.decode(new Uint8Array(client.data.shift()))

client.close()
server.close()

Which makes me suspect that issues is somewhere with-in our XPCOM implementation of TCPServerSocketAdapter that was mostly in place to workaround bug 1474150 which as far as I can tell has being fixed (as I get an error when trying to start multiple servers on the same port).

While I'm curious in figure what is broken, it might be more effective to just rip out XPCOM workarounds and start using TCPServerSocket instead, which I would expect would resolve the problem.

๐Ÿ‘๐Ÿผ๐Ÿ‘๐Ÿผ๐Ÿ‘๐Ÿผ