question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unhandled promise rejection - Error [ERR_HTTP_TRAILER_INVALID]: Trailers are invalid with this transfer encoding

See original GitHub issue

What is your Scenario?

We have a whole test suite that began failing this weekend, due to an unhandled promise rejection - ERR_HTTP_TRAILER_INVALID error. The tests previously were passing for quite some time, running against headless Chromium browser.

What is the Current behavior?

The tests, intermittently, are making it all the way to the end of the test and then fail on closing, with the following error:

1) Unhandled promise rejection:
      
      Error [ERR_HTTP_TRAILER_INVALID]: Trailers are invalid with this transfer encoding
      at ServerResponse._storeHeader (_http_outgoing.js:445:11)
      at ServerResponse.writeHead (_http_server.js:312:8)
      at RequestPipelineContext.sendResponseHeaders (/Volumes/casesensitive/git/mc_testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/context.js:319:13)
      at Array.sendProxyResponse (/Volumes/casesensitive/git/mc_testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/stages.js:129:13)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at Object.run (/Volumes/casesensitive/git/mc_testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/index.js:19:9)

What is the Expected behavior?

Tests pass consistently.

What is your public web site URL?

Your website URL (or attach your complete example):

Your complete app code (or attach your test files):

This is a simple test as an example:

import {Selector, t} from "testcafe";

const username = Selector("#username");
const password = Selector("#password");
const btnLogin = Selector("button[value='log in']");
const recoverPwdMsg = Selector("div[class='feedback-block error section']");

async function login(user, pwd) {
    await t
      .typeText(username, user)
      .typeText(password, pwd)
      .click(btnLogin);
}

fixture`Mailchimp User Signin Tests`;

test.page`https://mailchimp.com/login`(
  "Signin with invalid user credentials: Invalid User: @login",
  async t => {
    await t.expect(username.exists).ok();
    await login("abc12345!", "abc12345!");
    await t.expect(recoverPwdMsg.exists).ok();
  }
);
Screenshots:

Steps to Reproduce:

  1. Go to: https://mailchimp.com/login
  2. Execute this command: Enter invalid credentials and click login
  3. See the error: Test steps and assertions complete successfully but test reports failure due to unhandled promise rejection.

Your Environment details:

  • node.js version: v14.17.2
  • browser name and version: Chrome 92.0.4479.0 (92.0.4515.159 / Linux 0.0 in Jenkins)
  • platform and version: macOS 10.15.7 (as well as Linux in Jenkins)
  • other: Have been using Testcafe 1.14.2. Issue also seen on 1.15.0. Unable to upgrade to latest Testcafe version due to outstanding iframe issues.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:21

github_iconTop GitHub Comments

7reactions
JoniVanderheijdencommented, Sep 27, 2021

If you’re one of those poor sods pulling this issue in through Testcafe and aren’t against using patch-package. This is the patch file that fixed it for us until testcafe pulls in the fix.

/patches/testcafe++testcafe-hammerhead+24.5.1.patch

diff --git a/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/builtin-header-names.js b/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/builtin-header-names.js
index 4762b6f..b7249df 100644
--- a/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/builtin-header-names.js
+++ b/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/builtin-header-names.js
@@ -32,6 +32,7 @@ exports.default = {
     accept: 'accept',
     contentEncoding: 'content-encoding',
     expires: 'expires',
+    trailer: 'trailer',
     serviceWorkerAllowed: 'service-worker-allowed',
     accessControlAllowOrigin: 'access-control-allow-origin',
     accessControlAllowCredentials: 'access-control-allow-credentials',
diff --git a/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/header-transforms/transforms.js b/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/header-transforms/transforms.js
index 7c2303d..d8eb2db 100644
--- a/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/header-transforms/transforms.js
+++ b/node_modules/testcafe/node_modules/testcafe-hammerhead/lib/request-pipeline/header-transforms/transforms.js
@@ -97,6 +97,7 @@ exports.forcedRequestTransforms = {
 };
 // Response headers
 exports.responseTransforms = {
+    [builtin_header_names_1.default.trailer]: skip,
     // NOTE: Disable Content Security Policy (see http://en.wikipedia.org/wiki/Content_Security_Policy).
     [builtin_header_names_1.default.contentSecurityPolicy]: skip,
     [builtin_header_names_1.default.contentSecurityPolicyReportOnly]: skip,
5reactions
Dmitry-Ostashevcommented, Sep 22, 2021

Thank you all for the information. We will research it and update this thread once we have any news.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error [ERR_HTTP_TRAILER_INVALID]: Trailers are invalid ...
Error [ERR_HTTP_TRAILER_INVALID]: Trailers are invalid with this transfer encoding at ServerResponse._storeHeader (_http_outgoing.js:424:11) ...
Read more >
using trailer header with http chunked transfer. How to set ...
Using trailer I am trying to set a cookie after the page streaming has started. the code below tries to set the cookie....
Read more >
Trailers are invalid with this transfer encoding - Bountysource
Error [ERR_HTTP_TRAILER_INVALID]: Trailers are invalid with this transfer encoding at ServerResponse._storeHeader (_http_outgoing.js:424:11)
Read more >
The Node.js API
11.3.16 NODE TLS REJECT UNAUTHORIZED=value . ... 15.2.18 DEP0018 Unhandled promise rejections. ... 19.11.76 ERR HTTP TRAILER INVALID.
Read more >
Node.js response.addTrailers() Method - GeeksforGeeks
Trailers will only be emitted if the chunked encoding is used for the response; if it is not (e.g. if the request was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found