Code Monkey home page Code Monkey logo

Comments (7)

rauchg avatar rauchg commented on May 18, 2024

One thing we could do is have polling send a noop packet when websocket connects to speed up the poll cycle.

from engine.io-client.

rauchg avatar rauchg commented on May 18, 2024

It also occurred to me that an elegant way to handle this is to fire events on the current transport when another potential upgrade transport connects.

from engine.io-client.

ruxkor avatar ruxkor commented on May 18, 2024

I am still not able to consistently reproduce this behavior. We were able to fix this by having the server send a ping packet after a successful probe was received.

Obviously, this is not The Right Way to do things, but it helps to close an opening poll transport in a reasonable amount of time. You can find the changes for this in my branch (I didnt request a pull because I hope somebody will provide a better solution for this)

from engine.io-client.

rauchg avatar rauchg commented on May 18, 2024

What do you think about sending a noop packet to the open transport after a probe connection is established?

from engine.io-client.

ruxkor avatar ruxkor commented on May 18, 2024

I am not sure if this is the right approach:

To give a context, I am posting a part of the maybeUpgrade function of the engine.io server. Please note the 'PLACEHOLDER' comment

Socket.prototype.maybeUpgrade = function (transport) {
  // [...]
  var self = this;
  function onPacket (packet) {
    if ('ping' == packet.type && 'probe' == packet.data) {
      transport.send([{ type: 'pong', data: 'probe' }]);
      /* PLACEHOLDER */
    } else if ('upgrade' == packet.type) {
      // [...]
    } else {
      transport.close();
    }
  }
  transport.on('packet', onPacket);
};

At first, I thought the issue could be solved be directly sending some information on the 'not-probed' transport.
something like self.sendPacket('ping','post-probe') The problem is, that sometimes the self.transport was not in a state to be able to send something --> Error

Same thing goes for self.transport.send([]); (well, the Socket calls it in flush, so it was clear it would fail too).

I "resolved" the issue by changing the ping function to accept also a custom pingInterval. Everything in the range from 500ms to 2000ms works consistently. But, as I said before, I doubt that specific time-based intervals are a good approach for this.

Maybe some kind of serialization would help on the client though? Something like "probe only when a poll connection is established", so it is guaranteed there is a poll connection going to the server, that can then be closed? Only thinking aloud here though, but I'd love to see some good ideas we could try to implement.

from engine.io-client.

rauchg avatar rauchg commented on May 18, 2024

The key is to queue the packet on the Socket instead of trying to write it directly to the Transport (keep in mind that socket does the buffering, not the transport). And we also probably want to add a noop type to the protocol parser in engine.io-client.

from engine.io-client.

rauchg avatar rauchg commented on May 18, 2024

Fixed in engine.io

from engine.io-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.