idle event
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.6k
- Forks
- 2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 40
Description
There seems to be a use case with serverless functions, AWS Lambdas specifically:
You need to explicitly close the connection so the lambda can end properly, otherwise it will run until configured timeout is reached. And if you are doing many get/set calls you can't always know in a practical way which and when is the last one processed
let client;
function downloadXML(url) {
return new Promise( //code to download, resolve/reject );
}
function saveToReds(key, data) {
client.set(key, data);
}
exports.handler = async (event, context, callback) => {
client = redis.createClient(elastiCacheRedis);
someXML = await downloadXML(url);
objectsArrayXmlElements = libxmljs.parseXmlString(someXML);
objectsArrayXmlElements.forEach(
/*do stuff, then call saveToRedis(key, data); */
);
client.unref();
}
The code above will fail to write the first time to redis because client.unref() seems to be called before the file is downloaded and parsed. The weird thing is the second time the lambda function is run it will write correctly.
Using process.nextTick() didn't seem to make any difference, exactly the same behaviour
The only way it did work as expected was calling client.unref() inside the idle event.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the node-redis client’s idle event and unref() behavior, then reproduce the reported AWS Lambda flow with asynchronous set calls. Done should mean pending Redis writes complete reliably before the Lambda exits, without requiring a second invocation or manual idle-event workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, nodejs, redis
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100