-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Uncaught EmptyError when proxying after upgrading to Nest.js 8 #8111
Comments
Please provide a minimum reproduction repository. |
If I had to guess, this comes from the new use of |
@jmcdo29 Thanks for the quick reply! Here's a somewhat minimal repro, excised from our production code: |
Could it partly be the problem that It looks like this is working if I simply change: res.on('finish', () => subscriber.complete()) to: res.on('finish', () => {
subscriber.next();
subscriber.complete();
}); |
That could definitely be an issue as well. Because the proxy middleware is handling the response, when it gets back to Nest, Nest tries to send a response too, and that "Cannot set headers after they are sent to the client" gets triggered |
It seems that you already found the solution to your issue @david-golightly-leapyear so I'm assuming we can close this thread(?). As @jmcdo29 said, |
I have a workaround for the issue, but it feels like a hack. Is |
In a regular Nest app, there's no possibility that no values would be emitted to the stream (even if the method returns |
@kamilmysliwiec is proxying to a backend service not a use case handled by a "regular" Nest app? Can you tell me whether the implementation I have above is supported, or whether there is a more preferred approach? There might be a documentation change here if there is. |
We also observed this behavior, and fixed it by ensuring that the returned Observable emits at least one value (using |
Regression
Potential Commit/PR that introduced the regression**
Describe the regression
Before, the example code worked flawlessly. After Nest.js 8 upgrade, rxjs throws an uncaught
EmptyError
("no elements in sequence"). I can hide this by catching with anExceptionFilter
, but I'd like to know what's going on and whether this usage is still supported/whether I should be doing something differently. Note that none of the given error handlers catch this error. The stack trace is entirely within rxjs code:This was originally masked by this error:
but with an ExceptionFilter, I was able to catch the original error.
We're using
proxy
fromexpress-http-proxy
to forward data from a backend service (written in Haskell, and not a Nest.js microservice). We tried a couple more manual approaches, such as using Axios, but since we're using a custom payload format, it is a requirement that this Nest.js server proxy requests/responses transparently, without attempting to parse anything in the body and while supporting streaming as necessary, and express-http-proxy "just works" where Axios has been more tricky to figure out.I'm not even really sure what
EmptyError
means in this context; we can test that requests are correctly proxied, including headers & response bodies, so I'm not sure what's "empty" here when the functionality otherwise works as intended.I suspect there's something simple I'm missing; also. Thanks for reviewing!
Input Code
Expected behavior/code
No error.
Environment
The text was updated successfully, but these errors were encountered: