Coder Social home page Coder Social logo

Comments (1)

ruxkor avatar ruxkor commented on July 30, 2024

tl;dr
I have not quite wrapped my head around this one, but can it be possible that the hybi Socket object emits a readyState open, although the connection is actually already closed again?

some details

In order to visualize the whole procedure, I drew a callgraph, (handleUpgrade.dot.png)[https://github.com/ruxkor/engine.io/blob/master/docs/handleUpgrade.dot.png].

A small legend:

  • blue, dashed: synchronos process flow
  • blue, dashed: async process flow
  • green, solid: place where a function is constructed, and also called, if there is no other green, dashed arrow
  • green, dashed: where the function is called
  • red, dashed: assumed order if the asynchronous functions

combining the blue, solid arrow with the red, dashed arrows should present the actual flow of engine.handleUpgrade.

Back to the problem:
In ws.Websocket.establishConnection the object sets its own readyState on OPEN, after attaching the first and dataHandler to be called on process.nextTick and socket.on('data') respectively. It also attaches cleanupWebSocketResorces to its socket object. Only then it emits 'open',

Only then the w.io.hybi.WebSocket.onOpen (fn 1) will be called, which in turn attaches a function to process.nextTick, that will set the Sockets readyState on open and emit 'open'.

If a socket gets cleaned up, because of a sudden disconnect, I think the w.io.hybi.WebSocket (fn 1.1) will still be called, since it was already attached to process.nextTick.

possible solution
One possibility would be to check the readyState of the ws object inside (fn 1.1), and only set its own readyState and emit if it equals WebSocket.OPEN, similiar how the firstHandler is doing it in establishConnection.

An imo even better solution would be to implement getters and setters for the websocket.io.WebSocket readyState. In this way, it would be trivial to return th actual readyState, i.e. the one of the ws object, but still using an own attribute for the drafts.js WebSocket (since there is no ws attribute to use here).

from websocket.io.

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.