AWS Lambda, node, adm-zip: bad address in system call argument - node.js

Can create and read /tmp/temp.zip with AWS Lambda but this line causes an error:
var zip = new AdmZip("/tmp/temp.zip"); // https://www.npmjs.com/package/adm-zip
What does the error mean?
2018-08-08T13:23:41.074Z 2c1d866d-9b0e-11e8-8f32-8b0d6b822525 Error: EFAULT: bad address in system call argument, read
at Object.fs.readSync (fs.js:675:18)
at tryReadSync (fs.js:540:20)
at Object.fs.readFileSync (fs.js:575:19)
at new module.exports (/var/task/node_modules/adm-zip/zipFile.js:17:17)
at new module.exports (/var/task/node_modules/adm-zip/adm-zip.js:20:11)
at PassThrough.readStream.on (/var/task/index.js:28:19)
at emitNone (events.js:111:20)
at PassThrough.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
END RequestId: 2c1d866d-9b0e-11e8-8f32-8b0d6b822525
REPORT RequestId: 2c1d866d-9b0e-11e8-8f32-8b0d6b822525 Duration: 39773.72 ms Billed Duration: 39800 ms Memory Size: 128 MB Max Memory Used: 128 MB
RequestId: 2c1d866d-9b0e-11e8-8f32-8b0d6b822525 Process exited before completing request

The clue:
Memory Size: 128 MB Max Memory Used: 128 MB
So the lambda was running out of memory. Giving it 1024 MB solved the problem.

Related

When I try to connect to Redis from inside Kubernetes, always got connection failed

I have my node app deployed inside Kubernetes cluster, when the app tries to connect to Redis outside from the Kubernetes, it throws following error:
2019-09-04T06:21:55.320Z ioredis:redis status[101.37.199.xx:6379]: connecting -> connect
2019-09-04T06:21:55.321Z ioredis:redis write command[101.37.199.xx:6379]: 32 -> auth([ 'xxxxxx' ])
2019-09-04T06:21:55.321Z ioredis:redis write command[101.37.199.xx:6379]: 32 -> select([ '32' ])
2019-09-04T06:21:55.321Z ioredis:connection error: Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:146:25)
at writeGeneric (internal/stream_base_commons.js:137:3)
at Socket._writeGeneric (net.js:698:11)
at Socket._write (net.js:710:8)
at doWrite (_stream_writable.js:417:12)
at writeOrBuffer (_stream_writable.js:401:5)
at Socket.Writable.write (_stream_writable.js:301:11)
at Redis.sendCommand (/app/node_modules/ioredis/built/redis/index.js:601:33)
at Redis.select (/app/node_modules/ioredis/built/commander.js:124:21)
at Socket.<anonymous> (/app/node_modules/ioredis/built/redis/event_handler.js:32:18) {
errno: 'EPIPE',
code: 'EPIPE',
syscall: 'write'
}
[ioredis] Unhandled error event: Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:146:25)
at writeGeneric (internal/stream_base_commons.js:137:3)
at Socket._writeGeneric (net.js:698:11)
at Socket._write (net.js:710:8)
at doWrite (_stream_writable.js:417:12)
at writeOrBuffer (_stream_writable.js:401:5)
at Socket.Writable.write (_stream_writable.js:301:11)
at Redis.sendCommand (/app/node_modules/ioredis/built/redis/index.js:601:33)
at Redis.select (/app/node_modules/ioredis/built/commander.js:124:21)
at Socket.<anonymous> enter code here(/app/node_modules/ioredis/built/redis/event_handler.js:32:18)
2019-09-04T06:21:55.324Z ioredis:redis queue command[101.37.199.xx:6379]: 32 -> info([])
2019-09-04T06:21:55.324Z ioredis:redis status[101.37.199.xx:6379]: connect -> close
I've tried to deploy redis-cli inside the kubernetes cluster, it can access the redis service.
you have to expose redis as a service in your cluster

Intermittent redis connection error: 'UNCERTAIN STATE'

Time and time again, we get this error:
{ Error: Redis connection to some-redis-server:6379 failed - read ETIMEDOUT
at TCP.onStreamRead (internal/stream_base_commons.js:171:27) errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'read' }
{ AbortError: Redis connection lost and command aborted. It might have been processed.
at RedisClient.flush_and_error (/usr/src/app/node_modules/redis/index.js:362:23)
at RedisClient.connection_gone (/usr/src/app/node_modules/redis/index.js:664:14)
at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:289:14)
at Object.onceWrapper (events.js:281:20)
at Socket.emit (events.js:193:13)
at TCP._handle.close (net.js:614:12)
code: 'UNCERTAIN_STATE',
command: 'GET'
args: [ 'some-key' ] }
We are using https://www.npmjs.com/package/redis to access redis.
Some details of the setup:
Currently 25GB of data stored in Redis
Writes = a rate of approximately 2MB/sec.
Max number of concurrent clients connected: 400
I don't know where to really start looking, so any help would be appreciated.

lambda.invoke call through Node AWS SDK is timing out at 5 minutes while Lambda is completing under 4 minutes

I have a Lambda function that is set to timeout at 5 minutes, and occasionally when I invoke the function using the node SDK, I am getting a timeout error after 5 minutes.
However, when I have checked the CloudWatch logs after getting the client-side error, and am seeing the function successfully complete after ~3:30 minutes of execution time.
I have also noticed that the client side will log the timeout 2 minutes before the CloudWatch logs read that the function completed (ie, client side error timestamps at 4:08 and the CloudWatch successful end timestamps at 4:10), but I am assuming that is a lag between log writes, not run time. Thought I would mention it just in case that is something worth thinking more about.
From what I can tell, when the function runs under two minutes, it is consistently getting a positive response.
Code looks like this:
let aws_config = new AWS.Config({
region: 'us-east-1',
credentials: credentials,
httpOptions: {
proxy: process.env.HTTP_PROXY,
timeout: 300000
}
})
var lambda = new AWS.Lambda(aws_config);
lambda.invoke(params, (err, data: Result) => {
...
}
Error looks like this:
{ TimeoutError: Connection timed out after 300000ms
at ClientRequest.<anonymous> (.../node_modules/aws-sdk/lib/http/node.js:83:34)
at Object.onceWrapper (events.js:273:13)
at ClientRequest.emit (events.js:182:13)
at ClientRequest.EventEmitter.emit (domain.js:442:20)
at Socket.emitRequestTimeout (_http_client.js:661:40)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket.EventEmitter.emit (domain.js:442:20)
at Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:425:11)
message: 'Connection timed out after 300000ms',
code: 'TimeoutError',
time: 2018-10-05T20:08:35.719Z,
region: 'us-east-1',
hostname: 'lambda.us-east-1.amazonaws.com',
retryable: true } 'TimeoutError: Connection timed out after 300000ms\n at ClientRequest.<anonymous> (.../node_modules/aws-sdk/lib/http/node.js:83:34)\n at Object.onceWrapper (events.js:273:13)\n at ClientRequest.emit (events.js:182:13)\n at ClientRequest.EventEmitter.emit (domain.js:442:20)\n at Socket.emitRequestTimeout (_http_client.js:661:40)\n at Object.onceWrapper (events.js:273:13)\n at Socket.emit (events.js:182:13)\n at Socket.EventEmitter.emit (domain.js:442:20)\n at Socket._onTimeout (net.js:449:8)\n at ontimeout (timers.js:425:11)'
Have you looked into
context.callbackWaitsForEmptyEventLoop = false;
Here'e a related SO posting:
Why does AWS Lambda function always time out?

how to pass a object inside the logger.log() file in winston#3.0.0 in nodejs

i have a http request in a variable queryData = qs.parse(requestBody);
when i try to parse through winston
logger.log("info","requestbody",+queryData);
even tried
logger.log("info","requestbody %s", queryData);
logger.log("info","requestbody",{queryData});
didn't worked
am getting error like:
{ TypeError: Cannot create property 'Symbol(level)' on string 'Registering Device typeac'
at DerivedLogger.log (/home/grl/www/node_modules/winston/lib/winston/logger.js:130:20)
at createOcfRes (/home/aol/www/iot-node-server.js:285:10)
at IncomingMessage.<anonymous> (/home/aol/www/iot-node-server.js:115:9)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:186:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) level: 'error', timestamp: '19-07-2018 20:20:19' }

EventEmitter memory leak. require('request')

while using the request module by mikael I'm running the following:
if(product.Links.Direct_Link)
{
var string = product.Links.Direct_Link;
console.log(string)
request({'uri': string, 'jar': true, 'followRedirects': false, 'maxSockets': 15, 'headers': { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"}}, getSizes);
} else {
callback(null, product);
}
this is the output from this:
(node) warning: possible EventEmitter memory leak detected. 11 listeners added.
Use emitter.setMaxListeners() to increase limit.
http://www.spartoo.dk/Palladium_BARROW_KID-x30475.php?sx=G
Trace
at Socket.EventEmitter.addListener (events.js:160:15)
at Socket.Readable.on (_stream_readable.js:679:33)
at Socket.EventEmitter.once (events.js:179:8)
at Request.onResponse (C:\Vuuh\trunk\feedserver\node_modules\request\index.j
s:645:25)
at ClientRequest.g (events.js:175:14)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1669:21)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:120:23
)
at Socket.socketOnData [as ondata] (http.js:1564:20)
at TCP.onread (net.js:525:27)
I'm feeding a lot of http's to this request, as I want it to parse thousands of webpages.
The funny part is that I'm running it on another website and don't get this issue (that site has only 1/10 of the amount of pages though)?
Anyone got a pointer as to why I'm getting an eventemitter warning ? It makes the script run out of memory over time!
This is a bug of node #5108. Upgrade to the latest version(>0.10.11) of node should have solved the issue.

Resources