Skip to content

ECONNRESET and ECONNABORT errors when serving mp4 from public folder #12461

@Sektin

Description

@Sektin

Bug report

ECONNRESET and ECONNABORT error messages in strapi console

When I spam click F5 in the browser, I get ECONNRESET and ECONNABORT error messages in the strapi console.

Steps to reproduce the behavior

  1. Create a new strapi project version 3.6.8 or 4/latest
  2. Start strapi server
  3. Log in
  4. Go to Media Library
  5. upload a mp4 file
  6. create a simple html file containing a <video src="localhost:1337/uploads/upload_someHash.mp4 controls /> in the body
  7. open the html
  8. video should load an work normally
  9. you should see a 206 get request in the browser network tab and in strapi console
  10. start spam clicking F5
  11. you should encounter above mentioned errors after a while in the strapi console

Expected behavior

To not see these errors in the strapi console, because the connection reset or abortion should get handled somewhere.

Screenshots

2022-02-09 14_57_44-test html - strapi_test - Visual Studio Code

Code snippets

I can catch the error in node-modules/koa/lib/context.js in the onerror(err) function:

onerror(err) {
    // don't do anything if there is no error.
    // this allows you to pass `this.onerror`
    // to node-style callbacks.
    if (null == err) return;

    // When dealing with cross-globals a normal `instanceof` check doesn't work properly.
    // See https://github.com/koajs/koa/issues/1466
    // We can probably remove it once jest fixes https://github.com/facebook/jest/issues/2549.
    const isNativeError =
      Object.prototype.toString.call(err) === '[object Error]' ||
      err instanceof Error;
    if (!isNativeError) err = new Error(util.format('non-error thrown: %j', err));

    let headerSent = false;
    if (this.headerSent || !this.writable) {
      headerSent = err.headerSent = true;
    }

   console.log(err);

    // delegate
    this.app.emit('error', err, this);
...

I can see the koa-range package beeing involved creating the 206 partial-content response.
In node-modules/koa-range/index.js line 70:

...
console.log(ctx.response.header);
ctx.set('Content-Range', rangeContentGenerator(start, end, len));
ctx.status = 206;
...

I can catch the error and override it with my own console log in node-modules/strapi/lib/Strapi.js. But I don't like having to override node-module.

class Strapi {
  constructor(opts = {}) {
    this.reload = this.reload();

    // Expose `koa`.
    this.app = new Koa();

    this.router = new Router();

    this.initServer();

    // Logger.
    this.log = logger;

this.app.on("error", (error) => {
    if (error.code === "ECONNABORTED" || error.code === "ECONNRESET") {
      this.log.debug("video stream was aborted by client", { error });
    } else {
      this.log.error("Koa app-level error", { error });
    }
  });
...

I can also see the error in ./config/bootstrap.js. But this does not override the logger, I then get 2 messages in the console:

module.exports = async () => {
  console.log("bootstrap.js");
  strapi.app.on("error", (error) => {
    if (error.code === "ECONNABORTED" || error.code === "ECONNRESET") {
      strapi.log.debug("video stream was aborted by client", { error });
    } else {
      strapi.log.error("Koa app-level error", { error });
    }
  });
...

System

  • Node.js version: 14.16.0
  • NPM version: 6.14.11
  • Strapi version: 3.6.8 or 4/latest
  • Database: MySQL
  • Operating system: Windows 10

Additional context

A simple koa setup serves the mp4 with request 200 - no problems there
I have yet to build a simple koa setup using koa-range and serve the files with 206. Would be interesting to see what happens.
Opend a thread in the forums: https://forum.strapi.io/t/econnreset-and-econnaborted-triggered-by-mp4-after-reloading-browser/15473

My question is: Is it ok to just ignore these error messages? Nothing breaks or crashes, the videos play just fine. And if yes where would be the best place to catch them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: can not reproduceNot enough information to reproducestatus: will not fixWon't fix as it's either intended or for some other reason

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions