How does a try/rescue on a recursive function call affect the stack?

It’s actually not Observer’s fault - it is just displaying what it is getting back from process_info.

{current_stacktrace, Stack}
Returns the current call stack back-trace (stacktrace) of the process. The stack has the same format as returned by erlang:get_stacktrace/0. The depth of the stacktrace is truncated according to the backtrace_depth system flag setting.

Seems the default setting for backtrace_depth is 8 and once you increase its length it is allowed to grow further - though even then there seems to be some opportunistic dropping of “repetition” in order to capture more important (i.e. different) information in this “truncated stack log”.

So really it is more like a truncated process stack log rather than a true representation of the current process stack state (and the stack frames that reside on it).

iex(1)> 
12:34:50.885 [info]  Local close with reason: :normal
{:ok, pid} = EchoClient.start_link
{:ok, #PID<0.165.0>}
iex(2)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 44,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(3)> EchoClient.echo(pid, "Blah!")                      
12:39:27.526 [info]  Sending message: Blah!
:ok
iex(4)> 
12:39:27.576 [info]  Received Message: Blah!
iex(4)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 71,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(5)> WebSockex.send_frame(pid, :ping)
:ok
iex(6)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 89,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(7)> EchoClient.echo(pid, "Blah!01")                    
:ok
12:40:26.597 [info]  Sending message: Blah!01
iex(8)> 
12:40:26.647 [info]  Received Message: Blah!01
iex(8)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 98,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(9)> EchoClient.echo(pid, "Blah!02")                    
:ok
12:40:53.656 [info]  Sending message: Blah!02
iex(10)> 
12:40:53.708 [info]  Received Message: Blah!02
iex(10)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 107,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(11)> EchoClient.echo(pid, "Blah!03")                    
:ok
12:41:20.079 [info]  Sending message: Blah!03
iex(12)> 
12:41:20.129 [info]  Received Message: Blah!03
iex(12)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 116,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(13)> :erlang.system_flag(:backtrace_depth,100)
8
iex(14)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 233,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(15)> EchoClient.echo(pid, "Blah!04")                    
:ok
12:48:32.851 [info]  Sending message: Blah!04
iex(16)> 
12:48:32.898 [info]  Received Message: Blah!04
iex(16)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 251,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(17)> EchoClient.echo(pid, "Blah!05")                    
12:48:56.253 [info]  Sending message: Blah!05
:ok
iex(18)> 
12:48:56.300 [info]  Received Message: Blah!05
iex(18)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 260,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(19)> EchoClient.echo(pid, "Blah!06")                    
:ok
12:49:55.404 [info]  Sending message: Blah!06
iex(20)> 
12:49:55.452 [info]  Received Message: Blah!06
iex(20)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 278,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]
iex(21)> EchoClient.echo(pid, "Blah!07")                    
12:50:24.281 [info]  Sending message: Blah!07
:ok
iex(22)> 
12:50:24.354 [info]  Received Message: Blah!07
iex(22)> Process.info(pid,[:stack_size,:current_stacktrace])
[stack_size: 287,
 current_stacktrace: [{WebSockex, :websocket_loop, 3,
   [file: 'lib/websockex.ex', line: 409]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 463]},
  {WebSockex, :common_handle, 4, [file: 'lib/websockex.ex', line: 467]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]]