-
-
Notifications
You must be signed in to change notification settings - Fork 809
Description
Bug Report
I am currently testing using serverless offline to emulate an aws lambda that i will be deploying. It uses the default opensearch client to call an empty opensearch instance (with no data yet) running locally on my computer. When trying to return the search result I get the following error
× Uncaught exception
Environment: win32, node 22.11.0, framework 3.39.0 (local), plugin 7.2.3, SDK 4.5.1
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({})
at Worker.emit (node:events:507:17)
at Worker.emit (node:domain:489:12)
at [kOnErrorMessage] (node:internal/worker:326:10)
at [kOnMessage] (node:internal/worker:337:37)
at MessagePort.<anonymous> (node:internal/worker:232:57)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:816:20)
at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
I can console.log the content of the variable just before trying to return it with no problems, the output is as follows:
{
body: {
took: 6,
timed_out: false,
_shards: { total: 8, successful: 8, skipped: 0, failed: 0 },
hits: { total: [Object], max_score: 1, hits: [Array] }
},
statusCode: 200,
headers: {
'content-type': 'application/json; charset=UTF-8',
'content-length': '10917'
},
meta: {
context: null,
request: { params: [Object], options: {}, id: 1 },
name: 'opensearch-js',
connection: {
url: 'https://localhost:9200/',
id: 'https://localhost:9200/',
headers: {},
deadCount: 0,
resurrectTimeout: 0,
_openRequests: 0,
status: 'alive',
roles: [Object]
},
attempts: 0,
aborted: false
}
}Returning any other value inside this object, or any other value whatsoever, outputs the returned value normally to the lambda invoke requester.
I thought maybe the output was too large but I tested returning the content of a file with millions of characters, much large then the opensearch search output and it worked perfectly. Maybe there is a nesting limit but I could not find it.
Current Behavior
When trying to return the object I get an error.
Sample Code
- file: serverless.yml
service: my-service
plugins:
- serverless-offline
provider:
runtime: nodejs20.x
stage: dev
functions:
search:
handler: OpenSearchExample.search- file: OpenSearchExample.js
const { Client } = require("@opensearch-project/opensearch");
const host = "localhost";
const protocol = "https";
const auth = "admin:[OPENSEARCH_INITIAL_ADMIN_PASSWORD]"
const port = 9200;
const client = new Client({
node: protocol + "://" + auth + "@" + host + ":" + port,
ssl: {
rejectUnauthorized: false
}
});
exports.search = async () => {
response = await client.search()
console.log(response)
return {
body: response,
statusCode: 200
}
}- file: compose.yml
services:
opensearch-node1:
image: opensearchproject/opensearch:2
container_name: opensearch-node1
environment:
- cluster.name=opensearch-cluster
- node.name=opensearch-node1
- discovery.type=single-node
- discovery.seed_hosts=opensearch-node1
- bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD} # Sets the demo admin user password when using demo configuration, required for OpenSearch 2.12 and higher
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems
hard: 65536
volumes:
- opensearch-data1:/usr/share/opensearch/data
ports:
- 9200:9200
- 9600:9600 # required for Performance Analyzer
networks:
- opensearch-net
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:2
container_name: opensearch-dashboards
ports:
- 5601:5601
expose:
- '5601'
environment:
OPENSEARCH_HOSTS: '["https://opensearch-node1:9200"]'
networks:
- opensearch-net
volumes:
opensearch-data1:
networks:
opensearch-net:Expected behavior/code
To see on the invoker output the value that was printed to console.
Environment
serverlessversion: 3.39.0serverless-offlineversion: 13.6.0node.jsversion: 22.11.0OS: windows 11 win32