RangerMauve / hyperswarm-web

Implementation of the hyperswarm API for use in web browsers
MIT License
102 stars 15 forks source link

Error: Timeout at ProxyStream._handleError #19

Open elribonazo opened 2 years ago

elribonazo commented 2 years ago

Hello!

I'm really surprised with this marvelous peace of code, must say... I'm working on something weird that does not have any sense haha and i'm getting a weird issue.

The backend (hyperswarm) sends a hello message to the customer (hyperswarm-web) after they connect, I do this with the hyperswarm package as follows:


  const sw = Swarm();
  sw.on('connection', (connection, _info) => {
    try {
      connection.setKeepAlive(600);
    } catch (exception) {
      console.log('exception', exception);
    }
    const response = new Readable();
    response._read = () => {};
    response.push('Something weird');
    response.push(null);
    response.pipe(connection);
  });
  sw.join(
    id,
    {
      announce: true,
      lookup: true,
    },
    () => {
      console.log(`Listening on ws://${domain}:${port}`);
      console.log(`-> Proxy available on ws://${domain}:${port}/proxy`);
      console.log(`-> Signal available on ws://${domain}:${port}/signal`);
      server.listen(port);
    }
  );

The client side implementation is using the hyperswarm-web as I said and I only listen for connections and do the join. I initialize swarm only by passing the "bootstrap" attribute, nothing else.


events.js?b914:139 Uncaught Error: Timeout
    at ProxyStream._handleError (proxystream.js?6217:38)
    at HyperswarmProxyStream.emit (events.js?b914:158)
    at HyperswarmProxyStream._write (index.js?4892:115)
    at doWrite (_stream_writable.js?cf1e:409)
    at writeOrBuffer (_stream_writable.js?cf1e:398)
    at HyperswarmProxyStream.Writable.write (_stream_writable.js?cf1e:307)
    at Decoder.ondata (_stream_readable.js?2218:681)
    at Decoder.emit (events.js?b914:153)
    at addChunk (_stream_readable.js?2218:298)
    at readableAddChunk (_stream_readable.js?2218:280)
    at Decoder.Readable.push (_stream_readable.js?2218:241)
    at Decoder.Transform.push (_stream_transform.js?242d:139)
    at Decoder._push (decode.js?98dc:29)
    at Decoder._parseMessage (decode.js?98dc:58)
    at Decoder._transform (decode.js?98dc:82)
    at Decoder.Transform._read (_stream_transform.js?242d:177)
    at Decoder.Transform._write (_stream_transform.js?242d:164)
    at doWrite (_stream_writable.js?cf1e:409)
    at writeOrBuffer (_stream_writable.js?cf1e:398)
    at Decoder.Writable.write (_stream_writable.js?cf1e:307)
    at Duplexify.ondata (_stream_readable.js?8a17:619)
    at Duplexify.emit (events.js?b914:153)
    at addChunk (_stream_readable.js?8a17:291)
    at readableAddChunk (_stream_readable.js?8a17:278)
    at Duplexify.Readable.push (_stream_readable.js?8a17:245)
    at Duplexify._forward (index.js?3dd2:170)
    at Transform.onreadable (index.js?3dd2:134)
    at Transform.emit (events.js?b914:153)
    at emitReadable_ (_stream_readable.js?47d2:504)
    at emitReadable (_stream_readable.js?47d2:498)
    at addChunk (_stream_readable.js?47d2:298)
    at readableAddChunk (_stream_readable.js?47d2:278)
    at Transform.Readable.push (_stream_readable.js?47d2:245)
    at Transform.push (_stream_transform.js?6111:148)
    at WebSocket.onmessage (stream.js?35a2:167)

Is this because I'm not encoding the message before sending with SwarmEncode? I have no idea and help would be much appreciated!

RangerMauve commented 2 years ago

Would you be able provide a minimal repo which demos this error? It's a bit hard to know just from this snippet.

I think you'll need to periodically send packets down the connection regardless of the setKeepalive flag since I'm not sure if that's actually respected in web browsers.