Skip to content

Move websocket network connection creation to the resource task #6638

Closed

Description

@jdm

In the multiprocess world we can't initiate connections from the content process. Additionally, we need the initial websocket upgrade request to include things like cookies, etc. We need to add a new network protocol handler that takes care of all of this. The first step here is to simply move the connection creation out of the WebSocket constructor; we can leave the integration with the HTTP code for another time.

Code: components/script/dom/websocket.rs, components/net/resource_task.rs

Activity

  1. added
    A-content/dom
    E-more-complex
    on Jul 15, 2015
  2. samfoo commented on Jul 16, 2015

    @samfoo
    Contributor

    I'm willing to pick this up since I've hacked a bit on resource_task.rs already, but I'm not sure I understand what you're suggesting. Is the suggestion to move/recreate establish_a_websocket_connection in components/script/dom/websocket.rs to components/net/resource_task.rs, then instead of calling it in WebSocket::new, pass in the WebSocketResult as an argument?

  3. Ms2ger commented on Jul 16, 2015

    @Ms2ger
    Contributor

    Please don't pick it up just yet; I'm still working on that code.

  4. added
    S-blocked-on-external
    on Jul 16, 2015
  5. metajack commented on Jul 16, 2015

    @metajack
    Collaborator

    We can't allow network connections from the content sandbox? It seems a bit weird to proxy all this through some other process, although I guess if Gecko is single threaded for i/o this isn't much different to that.

  6. jdm commented on Jul 16, 2015

    @jdm
    MemberAuthor

    Gecko does the same. It's also important for things like network cache coherence, cookies, etc.

  7. metajack commented on Jul 16, 2015

    @metajack
    Collaborator

    Won't this prevent anyone from writing any high performance websocket code? That's a lot of data copying to go from JS to outside JS to another process and then into the final socket buffer and then all the way back for the reply.

  8. jdm commented on Jul 16, 2015

    @jdm
    MemberAuthor

    We may be able to send the socket descriptors to the content process after the connection is initiated. I haven't looked closely at what Gecko does for websockets in particular.

  9. metajack commented on Jul 16, 2015

    @metajack
    Collaborator

    That sounds satisfactory.

  10. removed
    S-blocked-on-external
    on Aug 26, 2015
  11. nfallen commented on Oct 27, 2015

    @nfallen

    I can work on this!

  12. added
    C-assigned
    on Oct 27, 2015
  13. jdm commented on Oct 27, 2015

    @jdm
    MemberAuthor

    For those following along at home, this is the plan I proposed to @nfallen:

    1. Extract the websocket networking code (ie. making a connection, receiving data, and sending data) out of components/script/dom/websocket.rs and into components/net/websocket_loader.rs (which doesn't exist). This will require communicating with the resource task (components/net/resource_task.rs) to instruct it to initiate a new websocket connection, and providing an API that allows receiving feedback about this process (and subsequently sending and receiving data)
    • I imagine this requiring a new message in the ControlMsg enum in components/net_traits/lib.rs similar to the existing Load message
    • The new message should take an IpcSender argument that would allow the DOM websocket code to listen for the result of the connection
    1. Extract the code in load in http_loader.rs that specifically deals with modifying the headers for a request into a separate function. Similarly, extract the code that deals with processing the headers for a response into a separate function.

    2. Use the new methods on the headers fields in the Request and Response types that exist in the websocket network connection code that now lives in websocket_loader.rs

  14. 11 remaining items

  15. nfallen commented on Dec 7, 2015

    @nfallen

    I am running the tests in wpt/web-platform-tests/websockets now. When they are run all together, one test times out every time, but when I run smaller subsets of the tests they all pass. Do you think this is just because of the decrease in performance of this implementation? Are there any other tests I should be running before creating a pull request?

  16. jdm commented on Dec 7, 2015

    @jdm
    MemberAuthor

    Huh, that's really interesting. Easiest way to figure it out is to run the tests against a revision without your changes and see if there's a change in behaviour. You can also try build with --release and running the tests with --release to see if there's a difference.

  17. jdm commented on Dec 7, 2015

    @jdm
    MemberAuthor

    And no, those WPT tests should be all that's necessary.

  18. nfallen commented on Dec 7, 2015

    @nfallen

    Yep, I tried those things! The build from master did not time out, but the release build from my branch still had the same issue.

  19. jdm commented on Dec 7, 2015

    @jdm
    MemberAuthor

    It's quite interesting that the test doesn't time out when run in the group. Which one is it?

  20. nfallen commented on Dec 7, 2015

    @nfallen

    A different test timed out each time that I ran ./mach test-wpt websockets. However, the most recent time I ran the tests, they all passed. Must be dependent on the CPU usage of my OS as I'm running the tests or something?

  21. jdm commented on Dec 7, 2015

    @jdm
    MemberAuthor

    Plausible! If you think the work's ready, please make a pull request so we can start reviewing! If not, but you'd like another set of eyes to look at this timing out thing, please push your code to a branch of your fork and link it here.

  22. added a commit that references this issue on Dec 8, 2015
  23. KiChjang commented on Jan 9, 2016

    @KiChjang
    Contributor

    Is this still pending on the extraction of websocket connection algorithms out of websocket.rs and into websocket_loader.rs?

  24. jdm commented on Jan 9, 2016

    @jdm
    MemberAuthor

    I'll file new issues for any remaining pieces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/domA-networkC-assignedE-more-complex

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions