Code Monkey home page Code Monkey logo

Comments (7)

iafan avatar iafan commented on September 16, 2024

@erikdubbelboer see if #27 is similar (though the panic happens on websocket disconnect). I made the pull request to fix the panic I'm facing by just avoiding sending the messages on a connection that is about to be closed.

Speaking of using multiple tabs, I also found that their usage is pretty limited (and in my case, I also want better security/isolation between running tasks). DevTools protocol has the notion of Targets and browser contexts which might help here. But in my project I decided to go further and always use a throw-away docker container to run each command. See it here: https://github.com/iafan/hc

from godet.

erikdubbelboer avatar erikdubbelboer commented on September 16, 2024

I'm not using remote.Close so this is a different issue, your pull request will not fix this as in my case remote.isClosing will stay false.

I need to load as many pages as fast as possible so using throw-away containers is waaay too slow. That's why I'm using multiple tabs for lower memory usage and each tab is fetching different pages at the same time. I don't think Targets and browser contexts have anything to do with this, they seem to be for using safe browsing and being able to load pages into different context where they don't share cookies and local storage.

from godet.

raff avatar raff commented on September 16, 2024

I have just added an example of opening multiple tabs in parallel, since it seems to be a hot topic :)
I will check into your panic. Is this on Linux ? (I normally do all my testing on a Mac)

Regarding changing the API to better support of multiple tabs, it's an interesting idea and I have given it a little thought (again, somebody else had a problem with multiple tabs). While it would make the API more clear and easier to use, using multiple RemoteDebuggers is not really that bad and if you look at it, the RemoteDebugger object is pretty much all about managing the connected tab.

Anyway, again, I will give it some more thought. Thanks!

from godet.

raff avatar raff commented on September 16, 2024

Can you update and try again ?

from godet.

erikdubbelboer avatar erikdubbelboer commented on September 16, 2024

I can tell you that doesn't fix a thing without even trying. Here is the real problem:

I call Connect() which calls connectWs() which sets ws and starts readMessages() in a goroutine.
Now before this goroutine has done anything Connect() returns and my code calls NewTab() which in turn calls connectWs() again which starts another readMessages() gorountine.
Now at this point both goroutines actually start and both call socket() which returns the exact same ws (the one that got set with NewTab()). Then they both call ws.ReadMessage() on the exact same ws instance. gorilla/websocket is not designed to be thread safe at all so as you can see this makes things panic immediately.

The fix is to not call socket() in readMessages() but instead get the socket as argument. In this case the first readMessages() goroutine would just try to read from the ws that was closed when I called NewTab().

from godet.

raff avatar raff commented on September 16, 2024

Ok, please try now.

from godet.

erikdubbelboer avatar erikdubbelboer commented on September 16, 2024

Yes that fixes it 👍

from godet.

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.