moleculer-web icon indicating copy to clipboard operation
moleculer-web copied to clipboard

After 5 minutes i received an error.

Open ching2018 opened this issue 3 years ago • 9 comments

503 Service Unavailable I sended a request,but i got this response.

httpServerTimeout for settings moleculer-web and requestTimeout for moleculer broker config/settings

iI've set it up, but it still fails

I thought the cause might be the nodejs's requestTimeout. https://github.com/nodejs/node/blob/main/lib/_http_server.js#L383

ching2018 avatar Jun 20 '22 13:06 ching2018

Please create a repro example

icebob avatar Jun 20 '22 14:06 icebob

Please create a repro example

https://codesandbox.io/s/moleculer-api-routing-forked-cxfnr8?file=/services/api.service.js

ching2018 avatar Jun 20 '22 15:06 ching2018

@cheungchingli try use callOptions Screenshot from 2022-06-20 20-25-17

intech avatar Jun 20 '22 16:06 intech

"use strict";
import ApiGateway from "moleculer-web";
import Koa from "koa";
import bodyParser from "koa-bodyparser";
import cors from "@koa/cors";

export default (broker: any) => {
  return broker.createService({
    name: "test",
    mixins: [ApiGateway],

    settings: {
      server: false,
      port: 27566,
      httpServerTimeout: 100 * 60 * 1000,
    },

    dependencies: [
      // 'package'
    ],

    methods: {},

    async created() {
      const app: any = (this.app = new Koa());
      app.broker = app.context.broker = broker;
      app.use(cors());
      app.use(bodyParser());
    },

    async started() {
      try {
        let server = await this.app.listen(Number(this.settings?.port));
        server.requestTimeout = 100 * 60 * 1000;
        server.timeout = 100 * 60 * 1000;
        // server.keepAliveTimeout = 5000;
        console.info(`web server started on port ${this.settings?.port}`);
      } catch (error) {
        return this.broker.fatal(error);
      }
    },

    async stopped() {
      if (this.app.listening) {
        this.app.close((err: any) => {
          if (err) {
            return console.error("web server close error!", err);
          }

          console.info("web server stopped!");
        });
      }
    },
  });
};

how to set in this code?plz

ching2018 avatar Jun 20 '22 16:06 ching2018

@cheungchingli This code is fundamentally different from codesandbox. Create repro code with this, plz.

intech avatar Jun 20 '22 16:06 intech

plz wait a moment

ching2018 avatar Jun 20 '22 16:06 ching2018

@intech https://codesandbox.io/s/competent-cray-ct7zkl?file=/index.js

ching2018 avatar Jun 20 '22 17:06 ching2018

The http.server timeouts have changed in Node.js v18. The headersTimeout is set to 60000 milliseconds (60 seconds), and requestTimeout is set to 300000 milliseconds (5 minutes) by default. The headersTimeout is the time that is allowed for an HTTP request header to be parsed. The requestTimeout is the timeout used for an HTTP request.

ching2018 avatar Jun 22 '22 03:06 ching2018

Why this issue related to moleculer-web if you use Koa?

icebob avatar Jun 27 '22 18:06 icebob