Skip to content

fetch() hangs with redirec and no-cors #4647

@cdoublev

Description

@cdoublev

Bug Description

The promise returned by fetch(redirectedURL, { mode: 'no-cors' }) never resolves.

Reproducible By

import http from 'http'
import { fetch } from 'undici'

const a = http.createServer((req, res) => {
    console.log(req.url)
    res.writeHead(200).end()
}).listen(8080)

const b = http.createServer((req, res) => {
    res.writeHead(301, { Location: `http://localhost:8080${req.url}` }).end()
}).listen(8081);

(async () => {
  // Remove `{ mode: 'no-cors' }` and the promise resolves
  const response = await fetch('http://localhost:8081/abc', { mode: 'no-cors' })
  console.log(response.status)
  a.close()
  b.close()
})()

Expected Behavior

I expect the promise to resolve, assuming I have not missed anything in the Fetch specification that requires the current behavior.

Logs & Screenshots

Environment

Debian v12.12 / Node v24.10 / undici v7.16.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions