elixir-desktop / ios-example-app

xcode project wrapper around the Elixir TodoApp Desktop app to run on iOS
MIT License
72 stars 6 forks source link

can't reconnect at real device #10

Closed thehaigo closed 1 year ago

thehaigo commented 1 year ago

I put the iOS sample in the background and wait 30 seconds and come back, it will not reconnect and become inoperable.

The Android sample was not a problem.

iOS 16 devide iPhone SE 2nd gen Elixir 1.14.1 elrang 25.0.1

2023-03-30 00:13:59.481001+0900 todoapp[21387:5657675] [connection] nw_socket_handle_socket_event [C1:1] Socket SO_ERROR [9: Bad file descriptor]
2023-03-30 00:13:59.482905+0900 todoapp[21387:5657675] [connection] nw_socket_get_input_frames [C1:1] recvmsg(fd 41, 4 bytes) [57: Socket is not connected]
2023-03-30 00:13:59.483627+0900 todoapp[21387:5657675] [connection] nw_read_request_report [C1] Receive failed with error "Socket is not connected"
connection 0 did end
server did close connection 0
[error] GenServer Bridge terminating
** (FunctionClauseError) no function clause matching in Bridge.handle_info/2
    (wx 1.0.10) lib/bridge.ex:227: Bridge.handle_info({:tcp_error, #Port<0.4>, :enotconn}, %Bridge{events: [], funs: %{164 => #Function<1.14728739/2 in Desktop.Window.close_window>}, port: 52165, requests: %{}, send: &:gen_tcp.send/2, socket: #Port<0.4>, subscribers: [#PID<0.202.0>]})
    (stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
    (stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:tcp_error, #Port<0.4>, :enotconn}
State: %Bridge{events: [], funs: %{164 => #Function<1.14728739/2 in Desktop.Window.close_window>}, port: 52165, requests: %{}, send: &:gen_tcp.send/2, socket: #Port<0.4>, subscribers: [#PID<0.202.0>]}
[error] Process Bridge (#PID<0.203.0>) terminating
** (FunctionClauseError) no function clause matching in Bridge.handle_info/2
    (wx 1.0.10) lib/bridge.ex:227: Bridge.handle_info({:tcp_error, #Port<0.4>, :enotconn}, %Bridge{events: [], funs: %{164 => #Function<1.14728739/2 in Desktop.Window.close_window>}, port: 52165, requests: %{}, send: &:gen_tcp.send/2, socket: #Port<0.4>, subscribers: [#PID<0.202.0>]})
    (stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
    (stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Initial Call: Bridge.init/1
Ancestors: [Desktop.Env, Desktop.Sup, #PID<0.200.0>]
Message Queue Length: 1
Messages: [tcp_closed: #Port<0.4>]
Links: []
Dictionary: []
Trapping Exits: false
Status: :running
Heap Size: 987
Stack Size: 28
Reductions: 26431
connection 0 did fail, error: POSIXErrorCode(rawValue: 57): Socket is not connected
2023-03-30 00:13:59.524915+0900 todoapp[21387:5656348] [connection] nw_connection_set_state_changed_handler_block_invoke [C1] Cannot set state changed handler after cancel
2023-03-30 00:13:59.525024+0900 todoapp[21387:5658395] [connection] [C1 127.0.0.1:62922 tcp, local: 127.0.0.1:52165, definite, attribution: developer, server, prohibit joining] is already cancelled, ignoring cancel
dominicletz commented 1 year ago

I found the issue, but will have to think about the solution a bit more...

dominicletz commented 1 year ago

Thanks @thehaigo ! This has been fixed in https://github.com/elixir-desktop/ios-example-app/commit/7bee5a76d06df39c9f54ecc2d4034572e1caa8fc and the dependent libraries. Please upgrade desktop to v1.5 and bridge to v1.1 in your app and update Bridge.swift as in the commit - as well as YourApp.swift to call the Bridge.instance.reinit() function on state change.