Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-7570 Fix logging context for POST requests #2691

Merged
merged 1 commit into from
Apr 16, 2021
Merged

Conversation

stephencdaly
Copy link
Contributor

@stephencdaly stephencdaly commented Apr 16, 2021

There is an issue when body-parser middleware is added after an AsyncLocalStorage store is opened, where the async context is lost.

This is caused by a downstream dependency oh Express's POST body parser middleware as identified expressjs/body-parser#404.

More detail can be found https://nodejs.org/api/async_hooks.html#async_hooks_troubleshooting.

This ordering was also required in Toolbox when using a different library using async_hooks.

Change middleware ordering to fix this.

There is an issue when body-parser middleware is added after an
AsyncLocalStorage store is opened, where the async context is lost.

This is identified here https://stackoverflow.com/questions/64330910/nodejs-asynclocalstorage-getstore-return-undefined
, although no cause is identified.

This ordering was also required in Toolbox when using a different
library using async_hooks.

Change middleware ordering to fix this.
Copy link
Contributor

@sfount sfount left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar behaviour observed in Toolbox but not much context from the time alphagov/pay-toolbox@fc22472

Potentially we can submit an issue questioning the behaviour to have someone who knows the details of the urlencoded() body parser comment, it may be something we can pitch in to help fix upstream in express.

@sfount sfount merged commit 9fd4f14 into master Apr 16, 2021
@sfount sfount deleted the PP-7570-fix-logging branch April 16, 2021 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants