-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
RuntimeError: Event loop stopped before Future completed #167
Comments
I have the same Issue |
Hmm. |
Hi Logger: root Uncaught thread exception |
We need debug logging for component, not warning. |
I have the "SSH&Web Terminal" integration installed. But don't know how to look at the btmon :( My logs : 2020-11-23 10:24:06 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: joining |
OK. More questions:
|
Show also your ble_monitor config. |
Official version, flashed on SD card, on my RPi4
I have a Zigbee key (Pizigate) on my GPIO. It use the ttyS0 port. Working fine with ZHA I tried several config, the actual : ble_monitor: |
OK, thank you. Сan you throw off a longer log? I need two errors, and everything in between. |
|
Thank you. Tell me also, how is your raspberry connected to the network? Ethernet or WiFi? |
Ethernet |
Installed fresh HassOS 4.17 on my raspberry. I don't have any problems (however, I have an RPi3b+). I have no idea yet what this might be related to. Have you tried reinstalling the component? |
Yeah, i tried some reinstall |
I have the same issue.
|
@ibitas Thanks for the logs! |
@ibitas please also check the syslog for any suspicious errors. |
No, its a generic intel-based linux machine. |
Guys, I ask you to try the code from the |
Thank you! |
Done -> same error + 1 new (the last line) 2020-11-24 17:19:50 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: joining |
OK, thank you |
Updated code. Please, try again (replace aioblescan_ext.py content) |
worst, more error Logs
|
I am adding diagnostic "error" messages in an attempt to get closer to the point of failure. |
OK. Now we need to replace the content of the |
Sorry, all files must be replaced ( |
2020-11-24 19:04:22 DEBUG (SyncWorker_6) [custom_components.ble_monitor] Spawning HCIdump thread |
@vini59fr one more time please all files (I think I'm close) |
|
See #361 for my response |
Hi! I came here becaise I'm also getting this error in the logs. But it's a bit different. The addon works totally fine for about a week or so, and then this error starts appearing in the logs and all the sensors stop reporting data at the same time. Restarting the whole system fixes it. I'm using the full supervised system. Sensors are 8 LYWSDCGQ. I'm using an external dongle with a long antenna for maximum reception and I've disabled the internal bluetooth of the pi 4 so it shows up as hci0. Is there anything I can do? I saw the discussion on the issue but the python command doesn't help for me. Also it may be another issue as I saw the original person who logged it had this happening right from the start. For me it works well for ages. Really well actually, with the external dongle I see ones as far as the other side of the house without any issue. PS: Period is set to 60, active scan and discovery are on. |
Normally, you should set active_scanto False. this error is a nasty bug, for which it is hard to find the cause of the problem. Can you check the question asked in this post |
Thanks for looking into this! I run hassio supervised on top of Raspbian (I couldn't use HassOS as that box does a few more things). It's up to date (core-2021.6.4 and supervisor-2021.6.0) I assume I have to do this in the container? I have the terminal addon installed so I ran the first command but I get: So there is no sudo on that container. I don't think there's any point running it on the host OS because everything that's HA runs in docker. When I leave the sudo out I get 'getcap: command not found'. When I just run 'which python3' I get nothing. 'python3' is also not found. But again this is the optional terminal docker so I assume it's not where the actual python scripts run. The dmesg command returns this:
With the last line repeating hundreds of times :) PS: I turned active scan off now, will see if it stops the issue from happening. It only happens once a week or so so it'll take some time. |
The ssh add on doesn’t have proper sudo rights, you should use a proper ssh connection, e.g. with the program putty from a Windows pc. You should run these commands on the host system. It is strange though that it runs fine for a week and than stops working. There have been some firmware updates lately for Bluetooth in HAos, so probably also on Rasbian. Please check that everything is up to date with sudo apt-get update followed by sudo apt-get upgrade with the same ssh connection. Next reboot the full system. |
Ah ok! I tried it on the host system but getcap complained about a missing -f option (even though this is for readlink). However when I just do sudo getcap /usr/bin/python3 (which is what 'which' returns) I get no output whatsoever. My python version is 3.7.3 But I wonder if this really means anything if I run it on the host system - after all every docker container just has its own environment. It doesn't even have to be based on the same linux distro :) I update the host regularly but I'll try it again! |
I'm not sure either. This command is checking that you have the proper rights for python to use the Bluetooth. It sometimes happens that one has updated python, while the rights are still assigned to the old python version. In your case, it works for a while, and than stops with the above error. I have seen people who reported that Bluetooth went down (power off or power down) at the same time. so please check this next time it has failed with I also have seen someone who solved it by buying another Bluetooth dongle. |
Thanks, I'll try that status if it happens again! I don't think it's the dongle because it's a very expensive model (Sena UD100). It's not some no-name brand thing (the Sena is used a lot for bluetooth hacking). The Asus from that topic won't work for me as it doesn't have an external antenna connection. I need the external antenna to 'see' all my sensors. I currently have a TP-Link 8dBi antenna on it :) PS: Is there any way to get detailed logging from the python module? Like if it crashes? I think it's a software issue because if I reboot it works fine again. I'm pretty ok with debugging python but the problem is that everything is hidden inside docker containers which makes it more difficult for me, I have less experience with that. |
Not sure, but a quote from the faq that could be useful in your case:
|
Thanks, I will do that when it happens again! It usually takes a while before I notice but I'll keep an eye on it! |
It just happened again! Just did the trace here, I left it running about 2 minutes. But nothing was output. The bluetooth service was running as normal. I tried restarting it. Then I restarted the logging and lots of data came through again (though it took about a minute to start after I restarted the bluetooth service, strange enough!). The sensor info also started coming through again.. I'll see about making a script that does the same.. You're right, it looks like it's something weird on the OS side. Still software, but probably not within your mobile, because it works when I restart the OS service again. No wonder this is hard to debug :( |
I think this btmon command should be running before (and during) the actual problem occurs, so just turn it on and wait till the problem occurs. Next, you should be able to find the log in the file hcitrace.txt. It is normal that data is only updated after one minute, this is the period that is default 60 seconds in BLE monitor. During this period, it will only collect data and do some averaging, after the period the state will be updated. Anyway, it seems to be something on the OS side, I agree. I will try to find the post of the guy who made a script to restart the Bluetooth service in case of failure. But there has to be some kind of trigger to say it has failed. If I find the post, I'll let you know. Found it: #345 (comment) Read the entire post, maybe some hints that may give you a clue in finding the cause. I guess it's a similar problem, but also not solved. This guy just restarts Bluetooth every 15 minutes. |
Thank you! I will try doing this. Since I started looking into this, it has started happening every few hours rather than weeks, unfortunately. I think it's due to an update I did either on the pi or on home assistant itself. I also turned off active scanning as you mentioned it shouldn't normally be on, so I tried turning that back on just now to see if it makes a difference. I think btmon shouldn't wait 60 seconds though - the 60 seconds is just on the HA side right? But btmon should show the raw packet input. It was btmon that waits 60 seconds (or so) before showing data after I restart the service. I think something takes a while to start up there. It also shows a LOT of data, it's constantly running so fast I can't read anything :) I think this is because I live in a busy area and I use a big antenna on my BT adapter so it sees a lot around me. I see many devices in the log that aren't mine (not TH sensors but completely different ones like phones, smart speakers and even vacuum cleaners ;) ) Thanks for the link to the script! Looks like they are running it on another machine. I might make something else instead, like monitoring with btmon and restarting it if there's been no output for 2 minutes or so. Still, it would be great to get to the bottom of it. I see how the btmon command could be useful, it might show it always crashes with the same packet received. I'm a bit worried by logging to my pi though, the SSD I use on it is quite old and I'm afraid I'll wear it out because it's really seeing a lot of data. I might stream it somewhere else over the network instead. I'll update if I find anything. |
Yes, the 60 seconds was on the HA side, yes. BT might need some time to restart perhaps as well, don't know. All BLE messages will pass by, it (BLE monitor) will ignore all messages that don't follow one of the supported formats, but BTMON will probably show all BLE adv. that you receive (which can be a lot yes). Let me know if you find out. |
So, I've done several traces so far. Before it crashes there's always a hexdump and an invalid packet size warning, usually associated with a Harman Kardon Onyx 4 speaker. And then a close result. Strange enough the open/close loops do happen earlier in the logs too but it doesn't always lead to a crash. I don't have one of those speakers so it must be one of my neighbours'. In fact it crashes almost every other hour now (rather than once per week) so either a bug was introduced when I last updated the raspberry pi this weekend, or this neighbour just bought that device and it triggers the issues. Like I said I have a high gain antenna on my BT adapter, so I can see devices all over the house, but this means I see lots of my neighbours' as well. Like, really lots. I live in a busy city center apartment so that makes sense. I'm going to do some more investigation and digigng through those logs.. Perhaps I'll write a script that restarts the bluetooth stack if it doesn't see any input for more than 60 seconds or so. I'll see. I'll let you know! But as to the actual error I do think it's in the stack itself. |
It's been happening a lot lately, and as you say it's something in the OS itself that crashes, not in the ble_monitor module. I've made a workaround for now, a cron script I run every minute. I noticed that hcitool no longer sees a device when it's crashed, so this is an easier indication to check for than simply the output of btmon stopping.
(hcitool dev always outputs one line even when it sees no devices so if it sees one there's a minimum of 2 lines). It seems to work so far but I'll give it a while to make sure. I added some logging and I have seen several restarts in the log already. I hope this solves it. Though it's still weird and annoying that the stack itself seems to be crashing. It doesn't feel right leaving it like this. |
Yes, I can imagine that it doesn't feel right. One things that pops into my mind is checking the firmware version and see if there is an update available. |
I did that already but it actually seemed to make things much worse (previously it crashed once a week, now on average once per hour :) . I don't really know where to report it either to the stack developers. But it seems to work fine now. It'll lose one or two minutes of measurements but it's not a big deal. By the way thanks for all the information in tracking this down! |
I'd like to only mention that I recently discovered that I also have this issue. It looks like rebooting whole machine makes it work for some time at least - I mean it does work right now but I'll have to check out later if it still the case. For the record: System Health
Home Assistant Supervisor
|
I have the same issue with RuntimeError. It appears after some time and sensors ale no longer updated. |
Hello,
Only way to fix it is to reset entire Pi.
My custom restart solution have 30 seconds delay between executions and I never had a problem with bluetooth device become unresponsive. |
I'm moving your request to a new issue. |
Guys. Hcitool used for bt scanning does not work on bluetooth 5.x. You need to use bluetooth 4.x adapter. |
I'm also having this issue on a Odroid. It doesn't discover my device and therefor I started logging it to see if I could make something out of it and this is the only issue that shows up in the log file. |
Forgive me but I didn't understand which commands. I have to run to fix the issue..please help me |
Please post your message in #295 Also check the FAQ for possible solutions for this error |
Hi
My Passive BLE integration is no more working.
I deleted my "old" sensor (only 3 LYWSDCGQ) to start a new fresh install. But it's impossible to pair them :(
I have this Error on my logs
Logger: root
Source: custom_components/ble_monitor/sensor.py:595
First occurred: 14:58:48 (1 occurrences)
Last logged: 14:58:48
Uncaught thread exception
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/config/custom_components/ble_monitor/sensor.py", line 595, in run
self._event_loop.run_until_complete(btctrl[hci].send_scan_request(self._active))
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 614, in run_until_complete
raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
The text was updated successfully, but these errors were encountered: