Cannot reopen the App on Unbuntu 22.04
I can build the release without any issues to create TodoApp-1.1.0-linux-x86_64.run, which, when run, will install TodoApp at ~/TodoApp and run it smoothly.
However, if I close the app and then try to reopen it by clicking on the desktop icon or executing it from ~/TodoApp, I don't get the window to open. To resolve this, I need to execute pkill -f TodoApp, and after a few seconds, TodoApp will start successfully. But, if I close it again, we will encounter the same issue.
$ uname -a
Linux laptop 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Hm, unfortunately I can't reproduce that. I've updated some dependencies including desktop_deployment which does the actual binary generation. Can you try again with that? Also if the issues persists is there anything suspicious in the ~/TodoApp/tmp/log/* files?
Hm, unfortunately I can't reproduce that.
My linux laptop doesn't have Erlang or Elixir installed. I hope this isn't what makes the difference.
I've updated some dependencies including desktop_deployment which does the actual binary generation. Can you try again with that?
Will try later when I finish my workday or maybe during lunch time.
Also if the issues persists is there anything suspicious in the ~/TodoApp/tmp/log/* files?
Will check them 👍
I have updated the git repo, removed deps and _build folder, built the release again and the problem persists.
The problem from the logs is that the port is already in use. This is because when I close the the TodoApp window, the server continues to run, and when I click the icon of the TodoApp again it tries to start the server with the same port. Shouldn't the Elixir server close when the the app window is closed?
Relevant logs bit:
=====
===== LOGGING STARTED Thu Apr 18 13:34:51 BST 2024
=====
heart_beat_kill_pid = 421902
[error] Failed to start Ranch listener TodoWeb.Endpoint.HTTP in :ranch_tcp:listen([cacerts: :..., key: :..., cert: :..., ip: {127, 0, 0, 1}, port: 46060]) for reason :eaddrinuse (address already in use)
[error] Running TodoWeb.Endpoint with cowboy 2.12.0 at http failed, port already in use
[notice] Application todo_app exited: exited in: TodoApp.start(:normal, [])
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, {{:shutdown, {:failed_to_start_child, TodoWeb.Endpoint, {:shutdown, {:failed_to_start_child, {:ranch_listener_sup, TodoWeb.Endpoint.HTTP}, {:shutdown, {:failed_to_start_child, :ranch_acceptors_sup, {:listen_error, TodoWeb.Endpoint.HTTP, :eaddrinuse}}}}}}}, {:child, :undefined, TodoWeb.Sup, {TodoWeb.Sup, :start_link, [[]]}, :permanent, false, :infinity, :supervisor, [TodoWeb.Sup]}}}
(todo_app 1.2.0) lib/todo_app.ex:33: TodoApp.start/2
(kernel 9.2.3) application_master.erl:293: :application_master.start_it_old/4
Kernel pid terminated (application_controller) ("{application_start_failure,todo_app,{bad_return,{{'Elixir.TodoApp',start,[normal,[]]},{'EXIT',{{badmatch,{error,{{shutdown,{failed_to_start_child,'Elixir.TodoWeb.Endpoint',{shutdown,{failed_to_start_child,{ranch_listener_sup,'Elixir.TodoWeb.Endpoint.HTTP'},{shutdown,{failed_to_start_child,ranch_acceptors_sup,{listen_error,'Elixir.TodoWeb.Endpoint.HTTP',eaddrinuse}}}}}}},{child,undefined,'Elixir.TodoWeb.Sup',{'Elixir.TodoWeb.Sup',start_link,[[]]},permanent,false,infinity,supervisor,['Elixir.TodoWeb.Sup']}}}},[{'Elixir.TodoApp',start,2,[{file,\"lib/todo_app.ex\"},{line,33}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,293}]}]}}}}}")
heart: Thu Apr 18 13:34:53 2024: Erlang is crashing .. (waiting for crash dump file)
heart: Thu Apr 18 13:34:54 2024: Executed "/home/exadra37/TodoApp/TodoApp daemon" -> 0. Terminating.
With the TodoApp window visible:
─exadra37@laptop ~/TodoApp
╰─➤ ps aux | grep -i todoapp
exadra37 430425 0.0 0.0 2832 1592 ? S 13:37 0:00 /home/exadra37/TodoApp/releases/1.2.0/../../erts-14.2.4/bin/run_erl -daemon /home/exadra37/TodoApp/tmp/pipe/ /home/exadra37/TodoApp/tmp/log/ /home/exadra37/TodoApp/releases/1\.2\.0/\.\./\.\./erts-14\.2\.4/bin/erl -noshell \+sbwt none -heart -kernel inet_dist_use_interface \{127\,0\,0\,1\} -s elixir start_cli -mode embedded -setcookie LOZNLKTQ5GK4ZQ3UFBAPFCCLAILGMHGPAK3QYMVCJD7RIBZSVJ7Q\=\=\=\= -name todo_app_430323\@127\.0\.0\.1 -config /home/exadra37/TodoApp/releases/1\.2\.0/sys -boot /home/exadra37/TodoApp/releases/1\.2\.0/start -boot_var RELEASE_LIB /home/exadra37/TodoApp/lib -args_file /home/exadra37/TodoApp/releases/1\.2\.0/vm\.args -extra --no-halt
exadra37 430426 0.0 0.0 2912 1060 pts/5 Ss+ 13:37 0:00 sh -c /home/exadra37/TodoApp/releases/1\.2\.0/\.\./\.\./erts-14\.2\.4/bin/erl -noshell \+sbwt none -heart -kernel inet_dist_use_interface \{127\,0\,0\,1\} -s elixir start_cli -mode embedded -setcookie LOZNLKTQ5GK4ZQ3UFBAPFCCLAILGMHGPAK3QYMVCJD7RIBZSVJ7Q\=\=\=\= -name todo_app_430323\@127\.0\.0\.1 -config /home/exadra37/TodoApp/releases/1\.2\.0/sys -boot /home/exadra37/TodoApp/releases/1\.2\.0/start -boot_var RELEASE_LIB /home/exadra37/TodoApp/lib -args_file /home/exadra37/TodoApp/releases/1\.2\.0/vm\.args -extra --no-halt
exadra37 430427 0.8 1.3 89975748 436196 pts/5 Sl+ 13:37 0:03 /home/exadra37/TodoApp/erts-14.2.4/bin/TodoApp.smp -sbwt none -SDio 5 -Q 65536 -- -root /home/exadra37/TodoApp -bindir /home/exadra37/TodoApp/erts-14.2.4/bin -progname erl -- -home /home/exadra37 -- -noshell -heart -kernel inet_dist_use_interface {127,0,0,1} -s elixir start_cli -mode embedded -setcookie LOZNLKTQ5GK4ZQ3UFBAPFCCLAILGMHGPAK3QYMVCJD7RIBZSVJ7Q==== -name [email protected] -config /home/exadra37/TodoApp/releases/1.2.0/sys -boot /home/exadra37/TodoApp/releases/1.2.0/start -boot_var RELEASE_LIB /home/exadra37/TodoApp/lib -- -- -extra --no-halt
exadra37 430440 0.0 0.0 3764 112 ? S 13:37 0:00 /home/exadra37/TodoApp/erts-14.2.4/bin/epmd -daemon
exadra37 431734 0.0 0.0 9216 2252 pts/1 R+ 13:43 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn -i todoapp
After closing the TodoApp window:
╭─exadra37@laptop ~/TodoApp
╰─➤ ps aux | grep -i todoapp
exadra37 430425 0.0 0.0 2832 1592 ? S 13:37 0:00 /home/exadra37/TodoApp/releases/1.2.0/../../erts-14.2.4/bin/run_erl -daemon /home/exadra37/TodoApp/tmp/pipe/ /home/exadra37/TodoApp/tmp/log/ /home/exadra37/TodoApp/releases/1\.2\.0/\.\./\.\./erts-14\.2\.4/bin/erl -noshell \+sbwt none -heart -kernel inet_dist_use_interface \{127\,0\,0\,1\} -s elixir start_cli -mode embedded -setcookie LOZNLKTQ5GK4ZQ3UFBAPFCCLAILGMHGPAK3QYMVCJD7RIBZSVJ7Q\=\=\=\= -name todo_app_430323\@127\.0\.0\.1 -config /home/exadra37/TodoApp/releases/1\.2\.0/sys -boot /home/exadra37/TodoApp/releases/1\.2\.0/start -boot_var RELEASE_LIB /home/exadra37/TodoApp/lib -args_file /home/exadra37/TodoApp/releases/1\.2\.0/vm\.args -extra --no-halt
exadra37 430426 0.0 0.0 2912 1060 pts/5 Ss+ 13:37 0:00 sh -c /home/exadra37/TodoApp/releases/1\.2\.0/\.\./\.\./erts-14\.2\.4/bin/erl -noshell \+sbwt none -heart -kernel inet_dist_use_interface \{127\,0\,0\,1\} -s elixir start_cli -mode embedded -setcookie LOZNLKTQ5GK4ZQ3UFBAPFCCLAILGMHGPAK3QYMVCJD7RIBZSVJ7Q\=\=\=\= -name todo_app_430323\@127\.0\.0\.1 -config /home/exadra37/TodoApp/releases/1\.2\.0/sys -boot /home/exadra37/TodoApp/releases/1\.2\.0/start -boot_var RELEASE_LIB /home/exadra37/TodoApp/lib -args_file /home/exadra37/TodoApp/releases/1\.2\.0/vm\.args -extra --no-halt
exadra37 430427 0.8 1.3 89975748 437888 pts/5 Sl+ 13:37 0:03 /home/exadra37/TodoApp/erts-14.2.4/bin/TodoApp.smp -sbwt none -SDio 5 -Q 65536 -- -root /home/exadra37/TodoApp -bindir /home/exadra37/TodoApp/erts-14.2.4/bin -progname erl -- -home /home/exadra37 -- -noshell -heart -kernel inet_dist_use_interface {127,0,0,1} -s elixir start_cli -mode embedded -setcookie LOZNLKTQ5GK4ZQ3UFBAPFCCLAILGMHGPAK3QYMVCJD7RIBZSVJ7Q==== -name [email protected] -config /home/exadra37/TodoApp/releases/1.2.0/sys -boot /home/exadra37/TodoApp/releases/1.2.0/start -boot_var RELEASE_LIB /home/exadra37/TodoApp/lib -- -- -extra --no-halt
exadra37 430440 0.0 0.0 3764 112 ? S 13:37 0:00 /home/exadra37/TodoApp/erts-14.2.4/bin/epmd -daemon
exadra37 431760 0.0 0.0 9216 2272 pts/1 S+ 13:44 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn -i todoapp
Both outputs have the same PIDs for the TodoApp. The only difference on the output is the PID for the grep command.
If you start the app in dev mode with mix run --no-halt , then close the window, you can then see that the shell it's still attached to the Erlang VM, which only exits with the usual ctrl + c + c.
I can also replicate the issue with your app downloaded from https://diode.io/download/
I noticed that the app adds a menu bar and task bar icon from where I can quit and reopen the app later, but this isn't what I am using to close the app window.
Just to be sure we are on the same page, by closing the window, I mean clicking in the X at the top right corner of the window. To open the app again I search for it in my applications and then I click on the app icon.
Maybe the problem is because you only shutdown the server on a :close_window event if the the task bar is nil?
Code here:
if taskbar == nil do
OS.shutdown()
{:noreply, ui}
else
:wxFrame.hide(frame)
{:noreply, ui}
end
Yeah, the logic is that when there is a taskbar icon defined, then closing the window doesn't exit the app. But when there is no taskbar icon you should get the behavior you want.
In case you want both e.g. have a taskbar icon but also close the app when the only window is closed, then we would need to expose a new configuration for that I think.
For our diode.io app - what we're doing in addition though is that we're using epmd to find the running instance and bring it to the front when there is an attempt to open another instance. That logic though hasn't made it back to elixir-desktop yet. Now I think it would be nicer to generalize that away from epmd and instead use the existing http port collision for checking and signalling. (E.g. handle the error you see in the logs and instead ask the running instance to show() the main window again).
For our diode.io app - what we're doing in addition though is that we're using epmd to find the running instance and bring it to the front when there is an attempt to open another instance. That logic though hasn't made it back to elixir-desktop yet.
What I reported for the TodoApp can also be replicated in the diode app, therefore what you describe here doesn't work to reopen the Diode app on Linux, after closing it by clicking on the x. What you describe here only works to reopen the app from the task bar or from the menu.
See my comment above:
I can also replicate the issue with your app downloaded from https://diode.io/downlo
If you want we can have a Google meet cal for me to show it live with the diode app.