-
Notifications
You must be signed in to change notification settings - Fork 50
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
Lengthy delays in .loop() #126
Comments
I think I am also seeing this, https://discord.com/channels/327254708534116352/537365702651150357/1035672894761619547 |
@calcut Do you have some comments on this apparently new problem? |
Hmm, well this bit is new Adafruit_CircuitPython_MiniMQTT/adafruit_minimqtt/adafruit_minimqtt.py Lines 864 to 874 in aec7777
If the mqtt broker keeps providing a response to _wait_for_msg, then it will keep looping for ~10 seconds (_recv_timeout) before giving up. You could try adding a logger, or at least some print statements to verify if that is what is happening. |
have you tried with |
I tried with the default timeout of 0 as well as a few various values, though I'm not sure my issue is the same as the original one in this issue description |
Thanks for your response. Yes, the duration of call is about 10 s (I should have been more precise in my original message).
Unfortunately my knowledge of the MQTT protocol is poor --- I tried to simplify my application code to give minimal working example, but I'm not 100% sure that it is adequate to diagnose problem (for example, I don't subscribe in client in this mwe, so maybe there shouldn't be any communication at all (?). I will try to understand how to add logging/print statements to diagnose, as you suggest. |
interesting... I wouldn't call myself an expert either To debug... my strategy was essentially:
You could try printing all responses received, something like this:
|
I was using a locally-running mosquitto broker, if that helps |
This is definitely a problem for me too. I can't seem to get any combination of minimqtt running on a Matrix Portal M4. The loop call hangs for several seconds. Even with Asyncio, this blocks other coroutines and prevents updates to the RGB matrix. This is pretty bad for a device that claims to be IoT friendly and doesn't even have a useable MQTT client. |
I'll take another look today. What broker are you connecting to @jinglemansweep ? |
I'm actually considering taking a look myself after work commitments today. I'm no expert on MQTT protocol though. I'm using Mosquitto mainly because I want to integrate with Home Assistant. Having a self hosted broker is a must for my uses unfortunately. Happy to provide any help if needed. |
I've just tested with mosquitto running on a RPi, and also on a Mac.
I started with the simpletest: which appears to work fine (assuming the broker ip and port are specified in secrets.py) I also added this, but didn't observe any delays in the loop() function
That was with ESP32-S2 and Circuitpython 7.3.1 |
" I have a metro M4 somewhere, I'll try with that too." |
@jinglemansweep Maybe you could try this... the broker may be returning something that causes this loop to continue |
Is everyone who is having a problem using non-native networking I wonder? This function executes quite differently for "ESP32SPI", which will be what the M4 Matrix Portal uses. Adafruit_CircuitPython_MiniMQTT/adafruit_minimqtt/adafruit_minimqtt.py Lines 976 to 1005 in aec7777
I guess it doesn't return |
I will give this a go later this afternoon. I actually have another Matrix Portal M4 arriving today which I'll use for testing. |
great. _sock_exact_recv should raise OSError(errno.ETIMEDOUT)
which should be caught by _wait_for_msg
and cause the loop() to exit. If that isn't happening, see if you an figure out what is going on. |
@calcut thank you for suggestion on diagnostics and sorry for the delay in responding. When I put in those suggested print statements (8th message in this thread), I get: Thanks. |
So, I'm getting
Changing the above line to:
... fixes the issue. My RGB matrix updates with a decent framerate, with a I can confirm that I can publish MQTT messages and my application receives them and logs them without blocking the RGB matrix updates:
I'm using my project for testing: https://github.com/jinglemansweep/matrix-portal-asyncio I'm happy to submit a PR, but I only have Matrix Portal M4's to test with, so my change could break other boards. |
Actually, looking at
Adding the
So, the socket is receiving constant single zero bytes. Perhaps a better fix would be adding
|
Okay, that doesn't work for some reason. If
|
Okay, my mistake. That line should probably be:
With just that change, everything appears to be working as expected. |
The most recent suggestion of @jinglemansweep fixes the issue for me (RP2040 feather, with ethernet feather wing, talking to mosquitto broker on LAN). |
nice work @jinglemansweep, you up for doing a PR to fix it? |
Sure. I have a branch ready but didn't have permission to push to it |
This is on your end, you mean? A PR is fine. |
Yes, I usually create a branch, push my changes to my branch and submit a PR to get it merged into master/main I get permission denied when pushing my branch:
|
Added bytearray('\x00') to the list of expected "noop" returns from the socket.
Did you fork the repo? If you want to make a branch, do it on your fork; you can't make a branch on the |
Sorry, just realised you use the fork model: My PR from my fork is here: #127 |
There is a recent commit 48aba3c which causes a lengthy delay in calls to .loop() in one of my test programs, which did not occur prior to this commit.EDIT: Apologies, I made a mistake in identifying a specific commit. The commit tagged 5.5.2 shows the lengthy delay, and commits tagged 5.5.1 and 5.5.0 do not show the problem.
I am using an ethernet featherwing attached to a rp2040 feather. Running the test code below (a modified version of example programs for minimqtt) before and after commit shows a lengthy (several second) delay introduced in calls to .loop() (the third last line in code). Whereas prior to this commit, loop returns quickly; i.e., on order of specified timeout.
I'm running circuitpython 7.3.3, but I get identical slow behaviour with 8.0.0 and most recent version of minimqtt.
The text was updated successfully, but these errors were encountered: