Code Monkey home page Code Monkey logo

Comments (10)

mcollina avatar mcollina commented on May 19, 2024 1

I think we should improve the API with a few caveats:

  1. a max number of retries for reconnects that will emit an error on the client itself, so we can potentially let the application do something.
  2. an offline event, so that the app can do something
  3. make the requests error after a timeout

from undici.

mcollina avatar mcollina commented on May 19, 2024 1

Thanks for your efforts! I know these problems are hard and those kind of bugs elusive. If you’d still come and take a shot after some time, you are always welcomed!

from undici.

ronag avatar ronag commented on May 19, 2024 1

I think we could look at https://www.npmjs.com/package/reconnect-core for some inspiration.

from undici.

doesdev avatar doesdev commented on May 19, 2024

Well, I suppose the above is imprecise. While it does attempt to reconnect that isn't the heart of the issue. Rather, at the time it attempts to reconnect there are 0 callbacks in the queue for the client. Which leads to the lack of notification.

Still digging, but wanted to course correct the above line of thinking about what the core problem is.

from undici.

mcollina avatar mcollina commented on May 19, 2024

If you find the root cause, please send a PR!

from undici.

doesdev avatar doesdev commented on May 19, 2024

Got it, gonna do a quick PR and see if there any design tweaks needed with it. Thanks

from undici.

doesdev avatar doesdev commented on May 19, 2024

Okay, PR #12 is sent. As noted I went for what I thought would have the lowest chance of unintended consequences. That said it does feel slightly hacky. If you have thoughts on a better way to approach it I'd be glad to tackle it. Thanks

Sorry for all the noise. I'm going to work on a better solution that I feel confident doing a PR on.

from undici.

doesdev avatar doesdev commented on May 19, 2024

Those sound like nice enhancements that would definitely address my needs. I can take a stab at those over the next few days and see if I can come up with clean implementations of each.

from undici.

doesdev avatar doesdev commented on May 19, 2024

Unfortunately I haven't been successful tackling the proposed API updates. I did add a maxRetries option in this branch. However, the tricky part is that if a client is initialized against a non-listening URL it will never be placed in kQueue, as it will just hang in the reconnect process until maxRetries (if set) is hit.

That being the case the callback never gets into the queue and so all affected requests will remain hung even after we emit maxRetries and close the client.

Similarly, in that scenario it will never make it to the timer in order to execute the timeout error on the request. I've tried several methods of working around this, mostly by changing the order of operations around. For instance moving the if (!this.socket) connect(...) into the kQueue worker function, but this leads to other requests hanging indefinitely.

Similarly I've tried initializing the Request, wrapping the callback, and placing it in the queue before the call to connect but that has led to various other issues.

I'm sure there is a way to do this, but unfortunately I've put a good bit of time toward trying and have failed at every turn. I'm not sure if you might want to keep this issue open for any reason, so I'll leave it open for now but feel free to close it.

from undici.

ronag avatar ronag commented on May 19, 2024

I've seen this as well, it goes into a live lock loop of reconnecting.

from undici.

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.