metacall / faas

Reimplementation of MetaCall FaaS platform written in TypeScript.
https://dashboard.metacall.io
Apache License 2.0
14 stars 21 forks source link

Bug: Post requests dones't work locally #66

Open Mostafa-wael opened 3 months ago

Mostafa-wael commented 3 months ago

Description

Post requests don't work when using FaaS locally.

Details

After deploying the string manipulation example locally.

I ran curl http://localhost:9000/2604c2a8a4e4/examples-testing/v1/call/longest_repetition -X POST --data 'aaa' But it stuck and didn't return anything.

image

I found that the FaaS container shows this error when the function is called:

metacall_faas  | Server is running on the port 9000
metacall_faas  | examples-testing         | NodeJS Loader Error: NodeJS Loader could not convert the value of type 'Invalid' to N-API
metacall_faas  | examples-testing         | NodeJS Loader Error: NodeJS Loader could not convert the value of type 'Invalid' to N-API
metacall_faas  | examples-testing         | /metacall/dist/worker/index.js:82
metacall_faas  | examples-testing         |                         result: functions[fn.name](...fn.args)
metacall_faas  | examples-testing         |                                                   ^
metacall_faas  | examples-testing         | 
metacall_faas  | examples-testing         | Error: NodeJS Loader could not convert the value of type 'Invalid' to N-API
metacall_faas  | examples-testing         |     at process.<anonymous> (/metacall/dist/worker/index.js:82:51)
metacall_faas  | examples-testing         |     at process.emit (node:events:517:28)
metacall_faas  | examples-testing         |     at process.emit (node:domain:489:12)
metacall_faas  | examples-testing         |     at emit (node:internal/child_process:944:14)
metacall_faas  | examples-testing         |     at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
metacall_faas  | examples-testing         | 
metacall_faas  | examples-testing         | Node.js v18.19.0

image

This is the output of the metacall-deploy --inspect OpenAPIv3 --dev command:

[
  {
    "openapi": "3.0.0",
    "info": {
      "title": "MetaCall Cloud FaaS deployment 'examples-testing'",
      "description": "",
      "version": "v1"
    },
    "servers": [
      {
        "url": "http://localhost:9000/2604c2a8a4e4/examples-testing/v1",
        "description": "MetaCall Cloud FaaS"
      }
    ],
    "paths": {
      "/call/longest_repetition": {
        "post": {
          "summary": "",
          "description": "",
          "requestBody": {
            "description": "",
            "required": true,
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "str": {}
                  }
                }
              }
            }
          },
          "responses": {
            "200": {
              "description": "",
              "content": {
                "application/json": {
                  "schema": {}
                }
              }
            }
          }
        }
      }
    }
  }
]

image

Obviously, when I send the request again the container crashes:

image

image

viferga commented 3 months ago

Yes, this bug is related to this: https://github.com/metacall/core/issues/518

viferga commented 3 months ago

This can be solved after implementing metacallfms. This is available in version 0.8.1. This should also solve this: https://github.com/metacall/faas/issues/64

viferga commented 3 months ago

@HeeManSu once the linux distributable CI finishes, you can try to implement this.

In the worker, you will need to change the metacall_load_from_configuration_export to metacall_load_from_configuration, and then use call by name with metacallfms.

You have an example of the API here: https://github.com/metacall/core/commit/649a0546a42ee638ca68ee0d470c6ea4e3bdeb3e

Check the test, it's calling a function by passing the name of the function and the json as string directly. This will solve the problems related to the call.

The body parser for json can be removed and we can use plain text for the call and await with this.