-
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
sntp.sync in progress #3044
Comments
The existing |
I think that your use of xpcall is incorrect -- it ought to be:
otherwise the second sntp.sync is executed as part of computing the arguments to the xpcall. |
@pjsg: You mean, encapsulating a function call into another (lambda) function would help in catching panics? Well, I'll hopelessly try..., maybe I misunderstood your hint? TY! @nwf: The error "handling" in |
You can flatten that |
Ok, let's flat this down to even:
IMHO calling a core function (twice) simply shouln't kill the device - no more, no less. What about simply
I didn't dig deeper to decide if that can break other functionalities (as am not in the position to know the design-in-mind of the originator of that code). Your thoughts, bad/good idea for the next housekeeping round? |
I would reject that patch. Functions, core or not, must be allowed to raise errors, and asynchronous handlers must be coded to deal with them. Documentation patches to correct examples would be very welcome, tho'. |
I agree with you @nwf, that just commentig out obnoxious parts of the core is a strict 'no go'.
Another approach would be to make I simply suggest to drop the exception in that case (when an ongoing sync likes to tell "WIP, don't bother me further", it shouldn't raise an exception, but just keep silently working it out). But I'm a late adaptor, not seeing the big picture, just making (maybe silly) assumptions! "Docs patch": Well, that would be a red box saying "call 'sntp.sync' with care, as it might crash your box".. No offence ;-) |
There is a way to deal with it, and that is The reason to not just silently swallow I'm not opposed, in principle, to exposing the syncing state of the sntp module to Lua, but I don't think Speaking of documentation, the documentation update could actually be quite a bit more specific than a warning box; in particular, |
TY, recoding the project. All (most) BTT: Can you state a link where I can take part of editing the docs? I'm frustated on criss&cross searching on Github already, and magically forwarding to readthedocs... serious. |
You'll only need to You should not expect that you will be able to respond in Lua to memory allocation failures: invoking the handler will likely attempt to allocate memory and that's... not likely to work out well. It is possible that large allocation failures will have left enough heap around for the failure path to run, but don't bet on it. The small heap size is definitely a leaky abstraction on NodeMCU; use LFS aggressively and try to keep an eye on All exception sources should be documented, morally, but our documentation is... well, patches are welcome. Speaking of, the docs are right here in the source tree and are just mkdocs / Markdown files with some local conventions: https://github.com/nodemcu/nodemcu-firmware/tree/dev/docs . |
In the case of sntp.sync, you only need to call it once --
sntp.sync(nil,nil,nil,1) -- will probably do what you want. The
documentation ought to be updated to state that this is the preferred form.
This attempts to keep the clock in sync forever.
…On Fri, Feb 28, 2020 at 7:41 AM Nathaniel Wesley Filardo < ***@***.***> wrote:
You'll only need to pcall things that can raise exceptions and for which
crashing/rebooting on failure is not the desired action. In general,
exceptions are there to indicate programmer error or a pretty serious
problem. (I continue to think that colliding sntp.syncs is a problem as
it indicates that the network is pretty wedged or you're sampling way too
fast.)
You should not expect that you will be able to respond in Lua to memory
allocation failures: invoking the handler will likely attempt to allocate
memory and that's... not likely to work out well. It is possible that large
allocation failures will have left enough heap around for the failure path
to run, but don't bet on it. The small heap size is definitely a leaky
abstraction on NodeMCU; use LFS aggressively and try to keep an eye on
node.heap() as you test parts of your application.
All exception sources *should* be documented, morally, but our
documentation is... well, patches are welcome. Speaking of, the docs are
right here in the source tree and are just mkdocs / Markdown files with
some local conventions:
https://github.com/nodemcu/nodemcu-firmware/tree/dev/docs .
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3044?email_source=notifications&email_token=AALQLTMZCSDJFQWEPZX63ITRFEBALA5CNFSM4KZJYPIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENIMNXI#issuecomment-592496349>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALQLTNPKWIPJR65BOF5RYTRFEBALANCNFSM4KZJYPIA>
.
|
@pjsg sntp.sync(nil,nil,nil,1): BTT: I saw the problem (racing Easy thing to avoid, I first thought, but... it's 11 comments later, not to be soluted in near future :) ...(even thought of putting a metatable ( __call) to _G to catch all core raised shortcomings... badest idea ever so far, I know =) |
If you are selling products based on NodeMCU, you should use a different The correct version of |
ntp.org == 'our' project? ;) What's over:
Nothing new ;-) |
Just to clarify: no, |
Just to leave a conclusio: I had to accept, that Well, well, well...it took a while looping the concepts thru personal wetware, but was a fine lecture in does&dont's. And some shortcomings remain (in an other thread..)! TY both @pjsg&@nwf for keeping constitute on a noob! |
+Outcomings of <nodemcu#3044>
I think, I've broken the docs (!!! attention) dev...danjohn:patch-3 Anybody help me out that github jungle? ;-) |
Adding an empty line before and after the note might help. But not sure. Maybe the note about using the default server should be more prominent a bit further up. Maybe mentioning the error message this issue is about would help others to better understand why protected calling is useful. |
+Outcomings of <nodemcu#3044>
TY4response, @HHHartmann! "Adding an empty line before and after the note" doesn't help (in the preview, bunches of needed text is striked and shown in red). Maybe that's just the github preview gone mad, but I'm afraid of making such crumble going online. Any advices from regulars (nudging @pjsg @nwf @TerryE (sorry for that!)), please? |
One thing to note is that you wrote This is the way to generate a note in the text:
I don't know if your title is too long or if the text is not indented -- but I found this example in the mqtt documentation and it formats correctly. |
Actual behavior
Calling
sntp.sync()
breaks the box, issuing "PANIC: unprotected error in call to Lua API (samwere.lua:87: sync in progress)"Expected behavior
It's fine, that
smtp.sync()
observes an ongoing time sync attempt, but should keep calm (and maybe return an error), but definitely should not panic (+restart the device)!More complicating, there is no way(?) to find out if there is a sync on the way (there are several async code paths in that very project), other than try&crash. Not very deterministic.
One more complicating, even the suggested
pcall(sync)
freaks out the same way (how can that occur?)Test code
NodeMCU startup banner
The text was updated successfully, but these errors were encountered: