<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="301265" data-post-id="301265">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="D4no0" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/D4no0/120/33624_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  D4no0
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think this discussion should be done with OTP team, because I doubt that elixir will introduce changes to genserver that are incompatible with the erlang version.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301265" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-301265" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301265"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="301266" data-post-id="301266">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adw632" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adw632
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Membrane-Core-Team" data-username="mickel8" data-post="1" data-topic="58284">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mickel8/48/32154_2.png" class="avatar"> mickel8:</div>
<blockquote>
<p><code>GenServer.call</code> might fail when a process we try to execute a call on no longer exists.</p>
</blockquote>
</aside>
<p>Why does the process not exist?</p>
<p>Why is registry_id(room_id) still have a dead process id?</p>
<p>Of course a process can die at any point, and you can crash calling it, but perhaps you need the <a href="https://levelup.gitconnected.com/genserver-dynamicsupervisor-and-registry-the-elixir-triad-to-manage-processes-a65d4c3351c1" rel="noopener nofollow ugc">holy trinity</a> of a <code>Supervisor</code>, <code>DynamicSupervisor</code> and <code>Registry</code>, managing and restarting the rooms?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301266" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-301266" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301266"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="301267" data-post-id="301267">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mat-hek" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mat-hek/120/38168_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mat-hek
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Membrane Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, I appreciate you trying to find the reasoning behind the original decision. Just wanted to make it clear that the way it is designed just doesn’t work in some cases and you have to hack it one way or another. Probably by wrapping with <code>try-catch</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301267" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-301267" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301267"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="301270" data-post-id="301270">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adw632" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adw632
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="11" data-topic="58284">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>I’m not argueing that having that option wouldn’t be useful - it very much would be. I don’t see a way to get there now though. The decision for <code>:gen_server.call</code> had been made ages ago and <code>GenServer.call</code> mirrored it. I don’t think <code>GenServer.call_but_not_exit</code> is a great option as well. Unless this discussion is aimed at elixir 2.0 I’m not sure what this topic is meant to get to.</p>
</blockquote>
</aside>
<p>It’s actually to be logically consistent by default across a range of possibilities such as:</p>
<ul>
<li>
<p>If the called process does not exist you get an exception on the caller.</p>
</li>
<li>
<p>If the called process exists and crashes as the message is in flight you get an exception on the caller.</p>
</li>
<li>
<p>If the called process exists and the node hosting the process crashes as the message is in flight you get an execption on the caller.</p>
</li>
<li>
<p>If the called process exists and the process crashes after the message has been added to the process message queue but not yet processed, you get an execption on the caller.</p>
</li>
<li>
<p>If the called process exists and the node hosting the process crashes after the message has been added to the process message queue but not yet processed, you get an execption on the caller.</p>
</li>
<li>
<p>If the called process exists and the message is delivered and the processes begins processing the call and then crashes you get an exception on the caller.</p>
</li>
<li>
<p>If the called process exists and is delivered and then the node  crashes as the message is being processed you get an exception on the caller.</p>
</li>
<li>
<p>If the called process exists and is delivered and the process does not handle that call, you get an exception on the caller.</p>
</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301270" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-301270" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301270"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="301280" data-post-id="301280">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mickel8" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mickel8/120/32154_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mickel8
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Membrane Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>Unless this discussion is aimed at elixir 2.0 I’m not sure what this topic is meant to get to.</p>
</blockquote>
<p>Yeah, yeah, I know <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"> I just couldn’t find any official guidelines so I am just trying to understand how I should design my API. I am also curious about your points of view <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> I know that <code>call</code> was designed on purpose to raise when a process no longer exists so just trying to get the reasoning behind it.</p>
<p>Also, moving this to the Erlang forum might be a good option as that’s not Elixir thing</p>
<blockquote>
<p>Why does the process not exist?</p>
<p>Why is registry_id(room_id) still have a dead process id?</p>
</blockquote>
<p>We had a bug where a room could crash under some circumstances. After fixing the bug, a room is no longer <strong>expected</strong> to crash so we could keep our code and assume that there won’t be further crashes and GenServer.call always succeeds but this situation made me think on how our API should be designed and whether we should be prepared for a process to crash at any time or assume that it is not <strong>expected</strong> to crash.</p>
<p>The bigger context is that we execute GET request to get all room states. It happened to us that one of rooms crashed in the meantime and the whole request crashed returning 500 error code. If a user re-request all room states it will get correct response so maybe that’s how the system should work and as I said we should keep our code without wrapping it into try/catch.</p>
<p>Another problem is that you don’t know how <code>Room.get_state</code> is implemented. In case of HTTP requests it’s pretty easy as Phoenix handles every single request in a separate process but imagine you are calling this API on your own. You don’t know whether this function can raise or not. If you knew, you could wrap it in <code>try/catch</code>, spawn a separate Task for it (but with async_no_link) or just call directly <img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301280" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-301280" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301280"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="301284" data-post-id="301284">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lud" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/120/14382_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Membrane-Core-Team" data-username="mickel8" data-post="16" data-topic="58284">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mickel8/48/32154_2.png" class="avatar"> mickel8:</div>
<blockquote>
<p>we should be prepared for a process to crash at any time</p>
</blockquote>
</aside>
<p>I have been there, and it’s very bad. You will go against the Erlang philosophy of letting things crash sometimes, and will have to handle an infinite amount of possible errors at every layer of the application, in every module, etc. Really bad.</p>
<p>The hard part is to accept that yeah, stuff goes wrong sometimes, and there is not much you can do about it. I see two cases, 1. the code will fail 50% of the time. In that case isolate in processes and/or use try/rescue/catch. 2. the code is not expected to fail, failures are exceptional. Then do nothing, let something else retry, it can be the frontend, an Oban job, a Task… just let your supervisor handle that and you can focus on implementing features.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301284" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-301284" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301284"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="301287" data-post-id="301287">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adw632" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adw632
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Membrane-Core-Team" data-username="mickel8" data-post="16" data-topic="58284">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mickel8/48/32154_2.png" class="avatar"> mickel8:</div>
<blockquote>
<p>Another problem is that you don’t know how <code>Room.get_state</code> is implemented. In case of HTTP requests it’s pretty easy as Phoenix handles every single request in a separate process but imagine you are calling this API on your own. You don’t know whether this function can raise or not.</p>
</blockquote>
</aside>
<p>Yes any code can crash because of a missing process,  a dead node or a code error such as divide by zero. That’s ok, you either deal with it at design time because you expect it and know EXACTLY how to handle it, or you don’t really know about the possibility or how to handle something unexpected so the right thing to do is to “let it crash” and defer to policy decided in the layer(s) above to recover e.g. through the supervision tree.</p>
<p>In Elixir our code can be highly concurrent, perhaps down deep in your library code is using <code>Task.async_stream</code> to process a stream of items concurrently. Any error that occurs in the spawned task (e.g. due to bad data your function doesn’t handle) should crash the calling process, because you really don’t expect it to fail.</p>
<p>If you are coming from a static typed exception heavy programming language, you are unreasonably forced to declare all possible exceptions and code defensively and <em>exhaustively</em> and try and handle things you can’t reasonably do much about because you don’t have a process model like Elixir to recover and cleanup state when the happy path is violated, such as when a process dies that you expected to be alive. In these other defensive paradigms your code has to do all the work to detect and cleanup, so you write even more code to try and handle all eventualities because you MUST keep the global shared state consistent. Of course, incorrect programs with even more code than the necessary happy path can’t reasonably be expected to correctly handle all eventualities, more code means more bugs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301287" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-301287" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301287"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="301289" data-post-id="301289">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="adw632" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  adw632
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="lud" data-post="17" data-topic="58284">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lud/48/14382_2.png" class="avatar"> lud:</div>
<blockquote>
<p>I have been there, and it’s very bad. You will go against the Erlang philosophy of letting things crash sometimes, and will have to handle an infinite amount of possible errors at every layer of the application, in every module, etc. Really bad.</p>
</blockquote>
</aside>
<p>Exactly.</p>
<p>“Drugs are bad m-kay..”</p>
<p>But it really is a shift in thinking, it’s why Joe Armstrongs <a href="https://erlang.org/download/armstrong_thesis_2003.pdf" rel="nofollow">thesis</a> was so important, what seems the right thing just leads to more harm than good.</p>
<blockquote>
<p>How can we program systems which behave in a <em>reasonable</em> manner <strong>in the presence of software errors</strong>? This is the central question that I hope to answer in this thesis.<br>
Large systems will probably <strong>always be delivered containing a number of errors</strong> in the software, nevertheless such systems are expected to behave in a reasonable manner.<br>
To make a <strong>reliable</strong> system <strong>from faulty components</strong> places certain <em>requirements</em> on the system.</p>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301289" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-301289" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301289"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="301296" data-post-id="301296">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="D4no0" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/D4no0/120/33624_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  D4no0
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Not to mention that handling errors manually is error-prone <img src="https://forum.elixirforum.com/images/emoji/apple/joy.png?v=15" title=":joy:" class="emoji" alt=":joy:" loading="lazy" width="20" height="20"> , so this is basically an infinite circle of hell.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="301296" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-correctly-handle-genserver-call-exits-because-of-non-existing-process/58284/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-301296" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="301296"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>