Comments (9)
@metcoder95 FYI
from undici.
Yeah, that was my biggest concern when trying to mimic the Dispatcher being returned.
But just to understand clear, you suggest to instead of doing mimics of the dispatcher
we just do that for the dispatch; so it can be injected instead of the dispatcher
?
from undici.
Yea, something like that. The back-pressure mechanism if dispatcher is slightly broken.
from undici.
Dispatcher.dispatch
always receives the tasks and then return true
if it can receive further requets, otherwise false
. If false
is returned then it will emit a drain
event.
This gets more complicated with Agent
as the back-pressure is per opts.origin
and hence the drain needs to check for the corresponding origin
in the drain
event (not sure if this is actually working atm, need to check).
So far everything could work (although complicated).
The tricky part occurs when we have interceptors (e.g. retry
, redirect
) that perform sub dispatches. There are two ways this occurs (1) sub dispatches in the Handler
or (2) async logic in the interceptor dispatch. Not sure how to handle this or whether or not it's actually a problem.
from undici.
Dispatcher.dispatch always receives the tasks and then return true if it can receive further requets, otherwise false. If false is returned then it will emit a drain event.
Hmm, good point; this is something that is definitely missed from the current interceptor implementation.
The tricky part occurs when we have interceptors (e.g. retry, redirect) that perform sub dispatches. There are two ways this occurs (1) sub dispatches in the Handler or (2) async logic in the interceptor dispatch. Not sure how to handle this or whether or not it's actually a problem.
I might say that the biggest issue is that we are branching the chain of calls there. In theory, we should try to always reply with true|false
to allow backpressure do its things, but in truth we do it blindly without fully respecting that mechanism.
Specially on retry
that we just fork the chain and fail if we exhaust the retries, I do not think that under high-pressure we will behave well.
Maybe the best is to always mandate return the value of dispatch
so it can be called on any time, but I might need to draft a PoC to see if this is something feasible (I'm currently blindly saying it is).
from undici.
Another option to consider is tryDispatch
which will not take the request if the dispatcher is busy.
Dispatcher.tryDispatch(opts, handler, () => /* try again */)
and then we can deprecate the return value if dispatch and the drain event.
Possibly even deprecating all events from the Dispatcher
API.
from undici.
Or just add another param to dispatch
that changes the behavior from fire and forget to fire and retry, Dispatcher.dispatch(opts, handler, onDrain)
from undici.
A lot of work remaining: #3374
from undici.
Another option to consider is
tryDispatch
which will not take the request if the dispatcher is busy.
Dispatcher.tryDispatch(opts, handler, () => /* try again */)
and then we can deprecate the return value if dispatch and the drain event.
Possibly even deprecating all events from the
Dispatcher
API.
Do we want to deprecate them?
I provide my feedback based on the fact that we will preserve them, but if we want to tear them down then it is not valid anymore.
What will be the value of deprecating for this new API instead of the events?
from undici.
Related Issues (20)
- Node 22.3.0 regression: undici sends invalid origin header in some cases HOT 2
- fetch arrayBuffer() leaks random data from process memory HOT 18
- build: husky install is deprecated HOT 1
- Ability to externalize WASM was broken HOT 11
- Measure request latency HOT 3
- dns round-robin interceptor + cache HOT 3
- async dispatch handler helper
- Cannot convert argument to a ByteString because the character at index 46 has a value of 65286 which is greater than 255 HOT 2
- Undici.Request and AbortController doesn't work well HOT 22
- The RetryHandler receives a duplicate body when the server does not support Range requests. HOT 11
- Back-pressure doesn't work with sub dispatches
- Add generic type for opaque object for stream() and pipeline() HOT 2
- v7 HOT 5
- Feature: Rewrite ProxyAgent HOT 4
- Does not set TLS `servername` to the value of the `Host` header HOT 9
- Significant Slowdown in Requests When Using ProxyAgent HOT 3
- inconsistent setDate(0) behaviour between windows and linux HOT 1
- Nightly tests are failing HOT 4
- `UND_ERR_CONNECT_TIMEOUT` errors thrown when there is CPU intensive code on the event loop HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from undici.