nodejs / nodejs/undici

Back-pressure doesn't work with sub dispatches

Open
#3,376 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
7.7k
Forks
880
Avg merge
2d 16h
Merged PRs (30d)
68

Description

  1. No back-pressure for interceptor composed dispatcher through dispatch(opts, handler)
  2. Async backpressure broken for sub dispatches, i.e. Pool makes false assumptions that nobody else has dispatched anything to its children. There is no way to know if a child can receive additional work without calling dispatch first at which point the request is already queued and can't be dispatched to another non-busy child.
  3. Back-pressure is global even though children depend on the actual request options, e.g. Agent depends on opts.origin to pick its child and a 'drain' event doesn't necessarily mean that a request can be dispatched, which becomes a bigger issue due to 2.
  • Adding a get busy() property on the Dispatcher interface will not work due to 3.
  • Adding a 'busy' event to the Dispatcher interface will not work due to 3.

The only viable solution I can find is some kind of tryDispatch(opts, handler, onDrain) API with a onDrain(err) callback and keep dispatch(opts, handler) as a fire and forget API and then deprecate the 'drain' event + boolean return value of dispatch(opts, handler):boolean.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the Dispatcher dispatch API through interceptor-composed dispatchers, Pool sub dispatches, and Agent child selection using request options. Review how the current drain event and boolean return value are consumed. Done requires an agreed design that preserves correct back-pressure across these cases and defines the replacement API behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.