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

Response.clone: Body has already been consumed. #977

Open
meold opened this issue Feb 19, 2025 · 8 comments
Open

Response.clone: Body has already been consumed. #977

meold opened this issue Feb 19, 2025 · 8 comments

Comments

@meold
Copy link

meold commented Feb 19, 2025

we have problem on production with supertokens-node 21.1.0 and Node.js v22.14.0.
it happens periodically (1 from 20-30 times)

TypeError: Response.clone: Body has already been consumed.
0|backend | at webidl.errors.exception (node:internal/deps/undici/undici:3384:14)
0|backend | at _Response.clone (node:internal/deps/undici/undici:8883:31)
0|backend | at Querier.sendRequestHelper (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/querier.js:378:47)
0|backend | at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
0|backend | at async Querier.sendGetRequest (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/querier.js:164:40)
0|backend | at async Object.getTenant (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/recipe/multitenancy/recipeImplementation.js:24:28)
0|backend | at async Object.isValidFirstFactor (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/recipe/multitenancy/utils.js:49:24)
0|backend | at async Object.filterOutInvalidFirstFactorsOrThrowIfAllAreInvalid (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/authUtils.js:654:28)
0|backend | at async Object.preAuthChecks (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/authUtils.js:94:39)
0|backend | at async Object.signInUpPOST (/home/ubuntu/core/backend/node_modules/supertokens-node/lib/build/recipe/thirdparty/api/implementation.js:97:35)

@deepjyoti30-st
Copy link
Contributor

@meold I tried to reproduce this but was not able to reproduce. I used node 22 with the same version of the SDK you mentioned. I had setup thirdparty login and tried multiple times (quite frequently) but the error did not happen.

Is it possible for you to share more details about your setup and perhaps any steps that definitely lead to the above error to happen?

Anything more to be able to reproduce this will be helpful.

@yyazupol
Copy link

@deepjyoti30-st I happened 1 from 100-200 times. We wrote the script to test this. And it happens sometimes on 10th attempt, sometimes on 156th attempt, and sometimes it works well.

@deepjyoti30-st
Copy link
Contributor

@yyazupol Can you share the script that was used? Would be helpful to be able to reproduce it.

@meold
Copy link
Author

meold commented Feb 27, 2025

@deepjyoti30-st it's applicatable only for our login page.

But I can give you concept:
[login_test.spec.js]

const { test, expect } = require('@playwright/test');
const fs = require('fs');
const path = require('path');
require('dotenv').config();

const logFilePath = path.join(__dirname, 'login_log.txt');

test.describe('check login', () => {
  const url = process.env.LOGIN_PATH);

  for (let i = 1; i <= 40; i++) {
    test(`login - Run ${i}`, async ({ page }) => {
      // Function for write log to file
      const logToFile = (message) => {
        fs.appendFileSync(logFilePath, `${new Date().toISOString()} - ${message}\n`);
      };

      // log only !=200 statuses
      page.on('response', async (response) => {
        const status = response.status();
        if (status !== 200) {
          const url = response.url();
          let logMessage = `Response: ${status} - ${url}`;

          // Add json responces
          if (response.headers()['content-type']?.includes('application/json')) {
            const body = await response.json().catch(() => null);
            logMessage += `\nResponse Body: ${JSON.stringify(body, null, 2)}`;
          }

          logToFile(logMessage);
        }
      });

      await page.goto(url);
      logToFile('Navigated to login page');

      // Click "Login with Google"
      const buttonGoogle = page.locator('svg[viewBox="0 0 326667 333333"]');
      await page.waitForTimeout(1000);
      await buttonGoogle.click();
      logToFile('Clicked Google button');

      // Enter email and password to GOOGLE
      await page.getByRole('textbox', { name: 'Email or phone' }).click();
      await page.getByRole('textbox', { name: 'Email or phone' }).fill(process.env.GOOGLE_USER_LOGIN);
      logToFile('Entered email');

      await page.getByRole('button', { name: 'Next' }).click();
      logToFile('Clicked continue button');

      await page.getByRole('textbox', { name: 'Enter your password' }).click();
      await page.getByRole('textbox', { name: 'Enter your password' }).fill(process.env.GOOGLE_USER_PASS);
      logToFile('Entered password');

      await page.getByRole('button', { name: 'Next' }).click();
      logToFile('Clicked login button');

      // Log out logic
      await page.getByAltText("User avatar").click();
      await page.locator("(//div[contains(text(),'Log out')])").click();
      logToFile('Logged out');

      await page.waitForTimeout(2000);
    });
  }
});

@meold
Copy link
Author

meold commented Feb 27, 2025

@deepjyoti30-st any updates?

@deepjyoti30-st
Copy link
Contributor

Hi @meold, yes, we have some updates here. The fix is almost there. I will open a PR for this soon and if everything is good, we should have the fix released soon.

@meold
Copy link
Author

meold commented Mar 10, 2025

@deepjyoti30-st when it will be added to updated npm version?

@deepjyoti30-st
Copy link
Contributor

Hi @meold we should have a release this week that will include this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants