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

fix: wrap middleware in promise #1119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

InsOpDe
Copy link

@InsOpDe InsOpDe commented Jul 7, 2022

this is necessary, so that async hooks work

#814
#1046

this is necessary, so that async hooks work
@InsOpDe
Copy link
Author

InsOpDe commented Jul 7, 2022

tests all pass.

no new tests have been added

@LinusU
Copy link
Member

LinusU commented Jul 7, 2022

Thank you for the PR! Currently there are unfortunately two problems which means we cannot merge it yet:

  • This is a breaking change, since Multer 1.x supports Node.js 0.10 which doesn't have Promise
  • If next throws an error that will be caught by us, and then we will call next again with that error. This is a very common misstake to make when trying to "callbackify" a promise. You can look here for some info on doing it the "correct" way: https://github.com/LinusU/util-callbackify/blob/master/index.js

@InsOpDe
Copy link
Author

InsOpDe commented Jul 7, 2022

Hi @LinusU do we have tests which check for your second point?

I wouldn't know how to fix the problem without promises. Should we close that PR then?

@LinusU
Copy link
Member

LinusU commented Jul 7, 2022

[...] do we have tests which check for your second point?

Not at the moment, but this would be a great to add!

I wouldn't know how to fix the problem without promises. Should we close that PR then?

One idea could be to only enable this path if typeof Promise === 'function'. I'm not to familiar with the context but I think that this can be solved without wrapping the entire thing in a Promise, instead using the async_hook module to track the context.

There seems to be some documentation here: https://nodejs.org/api/async_context.html

This could then be imported something like:

var asyncHook
try {
  asyncHook = require('async_hook')
} catch (_) {}

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