kirichkov / home_assistant-ble

Companion application for home-assistant, sending bluetooth low energy detection
21 stars 4 forks source link

crash when listed device found #12

Closed Spartan-II-117 closed 3 years ago

Spartan-II-117 commented 6 years ago

while running in terminal, upon discovery of a listed device from the config, home_assistant-ble crashes. stack trace: Just discovered D8:84:DF:14:DA:83 /usr/lib/ruby/2.1.0/net/http/response.rb:357:in finish': incorrect header check (Zlib::DataError) from /usr/lib/ruby/2.1.0/net/http/response.rb:357:infinish' from /usr/lib/ruby/2.1.0/net/http/response.rb:262:in ensure in inflater' from /usr/lib/ruby/2.1.0/net/http/response.rb:262:ininflater' from /usr/lib/ruby/2.1.0/net/http/response.rb:274:in read_body_0' from /usr/lib/ruby/2.1.0/net/http/response.rb:201:inread_body' from /usr/lib/ruby/2.1.0/net/http/response.rb:226:in body' from /usr/lib/ruby/2.1.0/net/http/response.rb:163:inreading_body' from /usr/lib/ruby/2.1.0/net/http.rb:1414:in block in transport_request' from /usr/lib/ruby/2.1.0/net/http.rb:1405:incatch' from /usr/lib/ruby/2.1.0/net/http.rb:1405:in transport_request' from /usr/lib/ruby/2.1.0/net/http.rb:1378:inrequest' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:129:in block in update_home_assistant' from /usr/lib/ruby/2.1.0/net/http.rb:853:instart' from /usr/lib/ruby/2.1.0/net/http.rb:583:in start' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:128:inupdate_home_assistant' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:91:in block in detect_new_devices' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:88:ineach' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:88:in detect_new_devices' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:66:inblock in run' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:64:in loop' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/lib/home_assistant/ble.rb:64:inrun' from /var/lib/gems/2.1.0/gems/home_assistant-ble-1.3.1/bin/home_assistant-ble:22:in <top (required)>' from /usr/local/bin/home_assistant-ble:23:inload' from /usr/local/bin/home_assistant-ble:23:in `

'

mikalstill commented 5 years ago

I'm seeing this too. Happy to help debug if required.

mikalstill commented 5 years ago

This seems to be a ruby issue where ruby for some reasons is trying to inflate something which wasn't compressed in the first place. I see bug reports against older versions of ruby for this.

mikalstill commented 5 years ago

Updating to the latest ruby with RVM didn't help.

kb5zuy commented 5 years ago

I'm running this on a RaspberryPI 3B with ruby 2.3.0. I had the same or similar issue; crash when receiving the response from homeassistant. BTW, I'm running HA 0.85.1 on a RaspberryPI 3B. I suspected an issue with deflating the response from HA, so I forced the accept-encoding header to 'identity' to disable compressed responses. That fixed the issue and it's now working. I do not believe that home_assistant_ble will every be transferring huge amounts of data, so this is probably an acceptable change - until ruby is fixed. Patch below or would you like a PR for this one-liner?

       def update_home_assistant(ha_conf, state)
         ha_name = ha_conf['name']
         uri = URI.join(home_assistant_url, "api/states/device_tracker.#{ha_name}")
         request = Net::HTTP::Post.new(uri)
         request.content_type = 'application/json'
+        request['Accept-Encoding'] = 'identity'
         request['X-Ha-Access'] = home_assistant_password if home_assistant_password
         request.body = state_update(ha_conf, state)
         req_options = { use_ssl: uri.scheme == 'https' }