nodejs / undici

An HTTP/1.1 client, written from scratch for Node.js
https://nodejs.github.io/undici
MIT License
6.24k stars 541 forks source link

native fetch produces duplicates - two identical request objects #1897

Closed kirrg001 closed 1 year ago

kirrg001 commented 1 year ago

Bug Description

I receive two identical request objects when doing a single fetch. Please help

Reproducible By

const diagnostics = require('diagnostics_channel')

diagnostics.channel('undici:request:create').subscribe(({ request }) => {
    console.log(request)
});

(async function() {
    console.log('fetching')
    await fetch('https://instana.com')
    console.log('fetched')
}())

Expected Behavior

Receive one event with status completed: true or two events with two different status.

Logs & Screenshots

Request {
  headersTimeout: 300000,
  bodyTimeout: 300000,
  throwOnError: false,
  method: 'GET',
  body: null,
  completed: false,
  aborted: false,
  upgrade: null,
  path: '/',
  origin: 'https://instana.com',
  idempotent: true,
  blocking: false,
  host: null,
  contentLength: null,
  contentType: null,
  headers: 'accept: */*\r\n' +
    'accept-language: *\r\n' +
    'sec-fetch-mode: cors\r\n' +
    'user-agent: undici\r\n' +
    'accept-encoding: br, gzip, deflate\r\n',
  servername: null,
  [Symbol(handler)]: {
    body: null,
    abort: null,
    onConnect: [Function: onConnect],
    onHeaders: [Function: onHeaders],
    onData: [Function: onData],
    onComplete: [Function: onComplete],
    onError: [Function: onError]
  }
}
Request {
  headersTimeout: 300000,
  bodyTimeout: 300000,
  throwOnError: false,
  method: 'GET',
  body: null,
  completed: false,
  aborted: false,
  upgrade: null,
  path: '/',
  origin: 'https://www.instana.com',
  idempotent: true,
  blocking: false,
  host: null,
  contentLength: null,
  contentType: null,
  headers: 'accept: */*\r\n' +
    'accept-language: *\r\n' +
    'sec-fetch-mode: cors\r\n' +
    'user-agent: undici\r\n' +
    'accept-encoding: br, gzip, deflate\r\n',
  servername: null,
  [Symbol(handler)]: {
    body: null,
    abort: null,
    onConnect: [Function: onConnect],
    onHeaders: [Function: onHeaders],
    onData: [Function: onData],
    onComplete: [Function: onComplete],
    onError: [Function: onError]
  }
}

Environment

v18.13.0 OSX

Additional context

mcollina commented 1 year ago

fetch automatically follows redirects. instana.com redirects to www.instana.com/. Hence, you have two requests.

kirrg001 commented 1 year ago

How to differentiate the two objects? As far as I can see they are identical

mcollina commented 1 year ago

They have different origin.