Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: following a 307 for a PUT with empty body fails #2027

Closed
macno opened this issue Mar 27, 2023 · 0 comments · Fixed by #2028
Closed

fetch: following a 307 for a PUT with empty body fails #2027

macno opened this issue Mar 27, 2023 · 0 comments · Fixed by #2028
Labels
bug Something isn't working

Comments

@macno
Copy link
Contributor

macno commented Mar 27, 2023

Bug Description

following an error with octokit, we discovered that a fetch with method PUT (but I guess also other methods too) and an empty body {body: ''} that receives a 307 from the server, fails with the code AssertionError [ERR_ASSERTION]: '' == true

this is the error we see with octokit

RequestError [HttpError]: fetch failed
    at /app/node_modules/@octokit/request/dist-node/index.js:110:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Job.doExecute (/app/node_modules/bottleneck/light.js:405:18) {
  status: 500,
  request: {
    method: 'PUT',
    url: 'https://api.github.com/repos/[REDACTED]/pulls/2764/merge',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit.js/2.0.7 octokit-core.js/4.0.5 Node.js/18.13.0 (linux; x64)',
      authorization: 'token [REDACTED]'
    },
    body: '',
    request: {
      hook: [Function: bound bound register],
      retryCount: 3,
      retries: 3,
      retryAfter: 16
    }
  }
}

Reproducible By

> const headers = {
..       accept: 'application/vnd.github.v3+json',
...       'user-agent': 'octokit.js/2.0.14 octokit-core.js/4.2.0 Node.js/18.15.0 (darwin; arm64)',
...       authorization: 'token [REDACTED]' };
> await globalThis.fetch('https://api.github.com/[redacted]/pulls/2772/merge', { method: 'PUT', headers, body: '' })
Uncaught TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:14062:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async REPL15:1:33 {
  cause: AssertionError [ERR_ASSERTION]: '' == true
      at httpRedirectFetch (node:internal/deps/undici/undici:13682:9)
      at httpFetch (node:internal/deps/undici/undici:13638:28)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async schemeFetch (node:internal/deps/undici/undici:13546:18)
      at async node:internal/deps/undici/undici:13422:20
      at async mainFetch (node:internal/deps/undici/undici:13418:20) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '',
    expected: true,
    operator: '=='
  }
}

Expected Behavior

that fetch follows the redirect without any error

Logs & Screenshots

Environment

we see the error with the following envs:

  • alpine 3.17 node 18.13 (amd64)
  • alpine 3.17 node 18.15 (amd64 / arm64)
  • macos 13.2.1 node 18.15 (arm64)

Additional context

Issue seems to be here because assert('') throws an error
I will propose to drop the assertion since a check that verifies body.source is not null is already present here

Happy to provide a PR if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant