-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Is there a race in eventmon? #1737
Comments
Lua is event-based and have only one "thread". So lua callbacks may not ever be called simultaneously. |
Thanks @djphoenix I now re-read the lua doc and can see how my code is safe, and does not even need the protection of However, the Should our doco (and examples) clarify this? Or is my understanding still lacking? |
@eyaleb as long as the event callback is registered before the event happens, it should always fire the callback. A simple way to ensure this is to register event callbacks at the beginning of The event handling for
|
@dnc40085 I think I now understand this process, thanks. Related though: if I unregister the event, will any corresponding queued task be removed? I expect so. My main point remains: registering a CONNECT event does not guarantee I will know that a connection was made. I must check the status too. In short, eventmon by itself is not enough, there is a timing issue (maybe 'race' in the title is inaccurate). |
Unfortunately, it seems I forgot to add a test for this when I implemented the event handler. thank you for pointing this out.
I believe the In further testing, I have found that the here is my test code (access point is already saved in flash) do
wifi.sta.setip({ip = "10.0.0.105", netmask = "255.255.255.0", gateway = "10.0.0.1"})
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP, function(T)
print("\n\tSTA - GOT IP\n\tREADY!")
end)
wifi.eventmon.register(wifi.eventmon.STA_CONNECTED, function(T)
print("\n\tSTA - CONNECTED\n")
end)
end |
@dnc40085 You are correct, however for this issue it does not matter if I use BTW, I tested, and the status is already 5 ( |
Can be considered resolved I guess. It's just a bit unfortunate that we've got both
but w/o giving recommendations as for when to use what that isn't really helpful. |
This is not a simple missed trigger bug but a design (SDK or nodemcu?) issue.
Expected behaviour
Registering an event should inform of the event happening.
Actual behaviour
The event does not always trigger.
Test code
If I do this early (to stop dhcp)
then (at times much) later I attend to the wifi
I usually see
However, if the registration is too late, after the connection is established, then no trigger is generated and a wdt reset takes place.
I do not see a simple way to ensure I always get notified. I now do this:
but is setting
handled
properly serialised?NodeMCU version
Latest
dev
Hardware
Any
The text was updated successfully, but these errors were encountered: