Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix :ack_request in response to AsyncConnection command #810

Merged
merged 1 commit into from Aug 1, 2023

Conversation

jjcarstens
Copy link
Member

@jjcarstens jjcarstens commented Aug 1, 2023

Using mode: :async can potentially result in Z/IP Gateway requesting and ACK response which was previously unhandled. This would eventually crash a CommandRunner process which incorrectly attempts to run this as a command

This fixes by adding in ack_request handling in AsyncConnection to match how SyncConnection is handling

Error Log
07:58:25.644 [error] GenServer #PID<0.14210.2> terminating
** (KeyError) key :name not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
    (grizzly 6.8.1) lib/grizzly/command_handlers/wait_report.ex:26: Grizzly.CommandHandlers.WaitReport.handle_command/2
    (grizzly 6.8.1) lib/grizzly/commands/command.ex:203: Grizzly.Commands.Command.do_handle_zip_command/2
    (grizzly 6.8.1) lib/grizzly/commands/command_runner.ex:64: Grizzly.Commands.CommandRunner.handle_call/3
    (stdlib 4.3) gen_server.erl:1149: :gen_server.try_handle_call/4
    (stdlib 4.3) gen_server.erl:1178: :gen_server.handle_msg/6
    (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.11620.2>): {:handle_zip_command, %Grizzly.ZWave.Command{name: :zip_packet, command_byte: 2, command_class: Grizzly.ZWave.CommandClasses.ZIP, params: [seq_number: 143, source: 0, dest: 0, secure: true, more_info: false, header_extensions: [{:encapsulation_format_info, %Grizzly.ZWave.Commands.ZIPPacket.HeaderExtensions.EncapsulationFormatInfo{security_classes: [:non_secure], crc16: false}}, :multicast_addressing], command: nil, flag: :ack_request], impl: Grizzly.ZWave.Commands.ZIPPacket}}
State: %Grizzly.Commands.Command{owner: #PID<0.11620.2>, retries: 0, source: %Grizzly.ZWave.Command{name: :battery_get, command_byte: 2, command_class: Grizzly.ZWave.CommandClasses.Battery, params: [], impl: Grizzly.ZWave.Commands.BatteryGet}, handler_state: %{complete_report: :battery_report}, handler: Grizzly.CommandHandlers.WaitReport, seq_number: 121, timeout_ref: #Reference<0.1017485277.4012900353.232010>, ref: #Reference<0.1017485277.4012638210.91220>, status: :queued, with_transmission_stats: false, transmission_stats: [], node_id: 14, supervision?: false, session_id: nil}
Client #PID<0.11620.2> is alive
    (stdlib 4.3) gen.erl:256: :gen.do_call/4
    (elixir 1.14.4) lib/gen_server.ex:1035: GenServer.call/3
    (grizzly 6.8.1) lib/grizzly/connections/command_list.ex:151: anonymous fn/3 in Grizzly.Connections.CommandList.get_response_for_command/2
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (grizzly 6.8.1) lib/grizzly/connections/command_list.ex:52: Grizzly.Connections.CommandList.response_for_zip_packet/2
    (grizzly 6.8.1) lib/grizzly/connections/async_connection.ex:174: Grizzly.Connections.AsyncConnection.handle_commands/2
    (grizzly 6.8.1) lib/grizzly/connections/async_connection.ex:158: Grizzly.Connections.AsyncConnection.handle_info/2
    (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
07:58:25.677 [error] GenServer {Grizzly.ConnectionRegistry, {:async, 14}} terminating
** (stop) exited in: GenServer.call(#PID<0.14210.2>, {:handle_zip_command, %Grizzly.ZWave.Command{name: :zip_packet, command_byte: 2, command_class: Grizzly.ZWave.CommandClasses.ZIP, params: [seq_number: 143, source: 0, dest: 0, secure: true, more_info: false, header_extensions: [{:encapsulation_format_info, %Grizzly.ZWave.Commands.ZIPPacket.HeaderExtensions.EncapsulationFormatInfo{security_classes: [:non_secure], crc16: false}}, :multicast_addressing], command: nil, flag: :ack_request], impl: Grizzly.ZWave.Commands.ZIPPacket}}, 5000)
    ** (EXIT) an exception was raised:
        ** (KeyError) key :name not found in: nil. If you are using the dot syntax, such as map.field, make sure the left-hand side of the dot is a map
            (grizzly 6.8.1) lib/grizzly/command_handlers/wait_report.ex:26: Grizzly.CommandHandlers.WaitReport.handle_command/2
            (grizzly 6.8.1) lib/grizzly/commands/command.ex:203: Grizzly.Commands.Command.do_handle_zip_command/2
            (grizzly 6.8.1) lib/grizzly/commands/command_runner.ex:64: Grizzly.Commands.CommandRunner.handle_call/3
            (stdlib 4.3) gen_server.erl:1149: :gen_server.try_handle_call/4
            (stdlib 4.3) gen_server.erl:1178: :gen_server.handle_msg/6
            (stdlib 4.3) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
    (elixir 1.14.4) lib/gen_server.ex:1038: GenServer.call/3
    (grizzly 6.8.1) lib/grizzly/connections/command_list.ex:151: anonymous fn/3 in Grizzly.Connections.CommandList.get_response_for_command/2
    (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    (grizzly 6.8.1) lib/grizzly/connections/command_list.ex:52: Grizzly.Connections.CommandList.response_for_zip_packet/2
    (grizzly 6.8.1) lib/grizzly/connections/async_connection.ex:174: Grizzly.Connections.AsyncConnection.handle_commands/2
    (grizzly 6.8.1) lib/grizzly/connections/async_connection.ex:158: Grizzly.Connections.AsyncConnection.handle_info/2
    (stdlib 4.3) gen_server.erl:1123: :gen_server.try_dispatch/4
    (stdlib 4.3) gen_server.erl:1200: :gen_server.handle_msg/6
Last message: {:ssl, {:sslsocket, {:gen_udp, {{{64768, 48059, 0, 0, 0, 0, 0, 14}, 41230}, #Port<0.2250>}, :dtls_gen_connection}, [#PID<0.11621.2>]}, [35, 2, 128, 144, 143, 0, 0, 7, 132, 2, 0, 0, 5, 0]}
State: %Grizzly.Connections.AsyncConnection.State{transport: %Grizzly.Transport{assigns: %{ip_address: {64768, 48059, 0, 0, 0, 0, 0, 14}, port: 41230, socket: {:sslsocket, {:gen_udp, {{{64768, 48059, 0, 0, 0, 0, 0, 14}, 41230}, #Port<0.2250>}, :dtls_gen_connection}, [#PID<0.11621.2>]}}, impl: Grizzly.Transports.DTLS}, socket: nil, commands: %Grizzly.Connections.CommandList{commands: [{#PID<0.14210.2>, #PID<0.13732.2>, #Reference<0.1017485277.4012638210.91220>}], keep_alive_command: nil}, owner: #PID<0.3632.0>, keep_alive: %Grizzly.Connections.KeepAlive{ref: #Reference<0.1017485277.4012900353.232011>, last_send: 1690898290114, interval: 25000, owner: #PID<0.11620.2>, command_runner: nil, node_id: 14}, node_id: 14}

Using `mode: :async` can potentially result in Z/IP Gateway requesting
and `ACK` response which was previously unhandled. This would eventually
crash a CommandRunner process which incorrectly attempts to run this as
a command

This fixes by adding in ack_request handling in AsyncConnection to match
how SyncConnection is handling
Copy link
Member

@bjyoungblood bjyoungblood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jjcarstens jjcarstens merged commit 4e46a06 into main Aug 1, 2023
1 check passed
@jjcarstens jjcarstens deleted the fix-async-ack_request branch August 1, 2023 17:32
@bjyoungblood bjyoungblood added the bug Something isn't working label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants