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

plug request option sends messages to self #316

Closed
danj3 opened this issue Mar 5, 2024 · 4 comments
Closed

plug request option sends messages to self #316

danj3 opened this issue Mar 5, 2024 · 4 comments

Comments

@danj3
Copy link

danj3 commented Mar 5, 2024

During development I optionally add a plug to requests to act as a loopback. The calling process is part of a GenServer. I started seeing spurious messages which I tracked down to happening somewhere in the run_request. The messages are 3-tuples {status, headers, response-body} and probably come from finch since send is plentiful there and none are in req.

Maybe this is a bug, or maybe the plug option isn't supposed (or safe) to be used this way. If it's just unsafe, this might be a warning in the docs. If it is a bug, then I might be able extract a small sample to reproduce. Also, if plug isn't good to use for this, is there an alternative that I missed?

@wojtekmach
Copy link
Owner

The messages are sent by Plug test adapter that Req uses for this: https://github.com/elixir-plug/plug/blob/v1.15.3/lib/plug/adapters/test/conn.ex#L101.

My suggestion is to use things like Bypass to spawn a server for your test and hit.

I’m gonna close this but please feel free to continue the discussion.

@wojtekmach
Copy link
Owner

I might be able to consume these messages in Req before returning to the caller as they are never meant to end up in the calling process.

@wojtekmach wojtekmach reopened this Mar 5, 2024
@danj3
Copy link
Author

danj3 commented Mar 5, 2024

I am injecting the plug not in a proper test, but to simulate the remote during development of other parts, to avoid making remote calls with undesirable side effects, instead of swapping the base url and making a local endpoint. the plug seemed like a simple way to do this, but now i understand that it’s using plug test and that i’m abusing the intended purpose.

of course if you can consume the messages, then i could abuse it this way. thanks for considering the possibility.

@danj3
Copy link
Author

danj3 commented Mar 5, 2024

changed dep to the 7c04 commit and this problem is resolved. Thank you!

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

No branches or pull requests

2 participants