-
Notifications
You must be signed in to change notification settings - Fork 113
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
shadow-delta-sample can be crashed with an existing shadow #52
Comments
I should add, this is a minimal reproducer I created after encountering this crash in my own program. I don't think it's a problem specific to shadow-delta-sample |
Hi @larsonmpdx , |
Thanks Varun! |
Hi @larsonmpdx , |
I did some more testing, this only happens when I have a lambda function enabled which writes a connected status to this device's shadow reported state based on the aws iot lifecycle event. it only happens sometimes (so it's some kind of race). the sequence is: click delete shadow in the gui then run shadow-delta-sample with the lambda function active. it will write a connected status back to the shadow reported state. sometimes this will cause a shadow-delta-sample crash I can try to create a simple lambda function to help you reproduce this, would that help? |
I changed shadow-delta-sample to debug loglevel and found the error happens after this line: I added a print statement after that line to see the shadow document:
it printed this before crashing (it got an empty shadow somehow?)
|
Hi @larsonmpdx , |
the problem feels like it's coming from an API call that sets the shadow (desired or reported) but doesn't trigger the generation of the delta state. I don't know how this all works but that's what I see happen in the gui when the crash happens. but it's an intermittent race thing so I might be fooling myself |
here is a node 6.10 lambda. I didn't have it actually process any data, it is just a convenient way to run the code. You can run it with the "test" button in the lambda gui. Fill in your own endpoint and thing name.
steps to reproduce:
this should crash shadow-delta-sample some portion of the time (about half the time for me). Here is my debug output of the most recent crash:
note there is no "desired" key in my payload, the SDK is looking for this key at this line: https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/src/shadow/Shadow.cpp#L237 |
Hi @larsonmpdx , |
Hi @larsonmpdx ,
Let me know if that works for you. |
the problem is trying to process JSON blobs assuming there are some keys there. line 237 assumes these keys: [SHADOW_DOCUMENT_STATE_KEY][SHADOW_DOCUMENT_DESIRED_KEY] if the state key is missing your fix will replace it. I posted debug output with this JSON:
The state key exists but the desired key does not, so your fix won't be triggered. I can still reproduce this crash. In general, anywhere in the SDK that you depend on JSON from the internet being formatted a certain way you need to test for the formatting first. Looking around the code there are other spots that need these tests as well. |
Hi @larsonmpdx , |
I'm using shadow-delta-sample unaltered except to add the sleep() call and some debug printing. SHADOW_DOCUMENT_EMPTY_STRING is unaltered you can see my debug printing shows the JSON delivered from the server, and in the given crash log it has a state key but no desired key within it. this happens sometimes when following the reproduction steps with the lambda function setting a reported state and adding a desired state by hand with the gui editor. the test |
Hi @larsonmpdx ,
The above change takes into consideration that the device might not have a desired state and merges the empty document with the cur_server_state_document_ before merging with the delta. This ensures it has desired and reported parts of the state. |
yes, that fixes it, thank you you can simplify the desired key check to this line and get rid of
|
Hi @larsonmpdx , |
add this line
after this line in shadow-delta-sample: https://github.com/aws/aws-iot-device-sdk-cpp/blob/master/samples/ShadowDelta/ShadowDelta.cpp#L197
this causes the sample to download the existing shadow without trying to modify it first. set this shadow online (the "welcome" tag gets put in there by the gui shadow editor):
the sample will run and crash this way when it downloads the shadow a few seconds after adding the subscription (before the sleep() call):
The text was updated successfully, but these errors were encountered: