derek-zhou

derek-zhou

I think you have a bug there. Generally, you need to keep a lookup table in the GenServer for all outstanding requests, keyed of an opaque token and pass the token down to the async process so you can figure which request is from which client and reply accordingly. You only have a field from_pid in the GenServer state, so concurrent clients are going to step on each other’s toe, the replies will get misdirected, and your clients will hang.

0
Post #920
zediogoviana

zediogoviana

Hum, good point! But, I believe the answer is yes and no :sweat_smile:
In my use case (where I used this) I knew for sure that the given GenServer was unique per user currently active in a specific part of the Web App, as pointed out in the Things to take into account part. This means there could be only one different caller in that situation, so the need to store only one pid.

However, what you said is true if that isn’t the case, and the example code by itself can be a bit misleading. I updated the Things to take into account section to highlight this situation. (Timeouts, and other possible issues still need to be taken care of by the user).
Does it make sense and do you think it’s more clear now?

Thanks for the comment!

0
Post #921
derek-zhou

derek-zhou

If your GenServer will not see concurrent usage, why go through all the trouble for deferred replies? You can just use a receive loop to wait from the response in the GenServer.

0
Post #922
zediogoviana

zediogoviana

To be honest, I didn’t think of that when applying this to my initial situation, and a receive do feels like a better approach, even if for just readability purposes… Still, my main goal with this post was just to show that this was possible to do and that it can help in specific situations, as it’s something that may slip through when reading the docs, or just getting started.

0
Post #923
derekkraan

derekkraan

“There are tremendous opportunities for commercial Elixir libraries.”

My interview with Parker Selbert, creator of Oban.

2
Post #924
resende

resende

My latest blog post on how to use exponential backoff in Elixir to handle unreliable external services.

0
Post #925
johantell

johantell

A post on how you can improve long time maintainability by decoupling external libraries.

1
Post #926
alexpls

alexpls

Here’s one on handling subscriptions and payments with Gumroad. I’d say the concepts are broadly applicable but implementation examples are taken from my Elixir/Phoenix webapp.

https://alexplescan.com/posts/2022/12/22/selling-saas-subscriptions-on-gumroad/

1
Post #927
realcorvus

realcorvus

Hi everyone, Paraxial.io now has guidance on how to fix each Sobelow finding. This documentation is also being published as open source, to benefit the Elixir community - Elixir Security: A Guide to Fixing Sobelow Findings

1
Post #928
ChristianAlexander

ChristianAlexander

I recently wrote a post on Server-Side Request Forgery (SSRF) attacks, from the theory of the attack to a naive set of mitigations and finally an import of SafeURL. All code samples are in Elixir!

4
Post #929