CodeGenieApp / CodeGenieApp/serverless-express
After middleware transiently not completed before lambda ends
- Vorherrschende Sprache
- JavaScript
- Sterne
- 5.3k
- Forks
- 676
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I recently ran into an issue where code that runs after a call to `res.json` in a given route is not guaranteed to be run before a lambda ends.
My use-case is as follows -
1. `PUT /posts/1`
2. handle database update in route
3. return updated record to client using `res.json`
4. as an _after_ middleware, send event specifying something was changed to AWS SQS
In a regular express server, I expect that the code in step 4 would complete successfully. However, I believe that serverless-express is ending the invocation of the lambda before that code has a chance to complete under certain circumstances.
To be a little more clear, here is a set of logs that represents a successful invocation -
```
START RequestId: d884deec-393a-40d2-93b3-f302d8f0c7fa Version: $LATEST
queuing change event
change event successfully queued
END RequestId: d884deec-393a-40d2-93b3-f302d8f0c7fa
```
and here is a set of logs that represents an unsuccessful invocation -
```
START RequestId: 0a1fc1e7-c8a8-40b0-bf80-076ce4c922e6 Version: $LATEST
queuing change event
END RequestId: 0a1fc1e7-c8a8-40b0-bf80-076ce4c922e6
```
As you can see, under some circumstances, the lambda invocation ends _before_ the process has a chance to complete writing to SQS.
Is it possible that this use-case is not well supported in serverless-express? Let me know if more information is needed or if I am obviously doing something wrong.
Beitragsleitfaden
Rechercherichtung
Beginne mit der Überprüfung des serverless-express-Lambda-Aufruflebenszyklus, insbesondere wie `res.json` mit after-Middleware und noch ausstehender asynchroner Arbeit interagiert. Reproduziere die gemeldete Route und das AWS-SQS-Protokollszenario; abgeschlossen ist die Arbeit, wenn das Verhalten zuverlässig behandelt wird oder seine Unterstützung und Einschränkungen klar dokumentiert sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- aws, express, javascript, node.js
- Bereich
- api, backend, cloud
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100