moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
292 stars 118 forks source link

After 5 minutes i received an error. #311

Closed ching2018 closed 1 year ago

ching2018 commented 2 years ago

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

icebob commented 2 years ago

Please create a repro example

ching2018 commented 2 years ago

Please create a repro example

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

intech commented 2 years ago

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

ching2018 commented 2 years ago
"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

intech commented 2 years ago

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

ching2018 commented 2 years ago

plz wait a moment

ching2018 commented 2 years ago

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

ching2018 commented 2 years ago

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.

icebob commented 2 years ago

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