@@ -311,6 +311,7 @@ int main(int argc, char *argv[])
311311 std::promise<void > subscribeGetShadowRejectedCompletedPromise;
312312 std::promise<void > onGetShadowRequestCompletedPromise;
313313 std::promise<void > gotInitialShadowPromise;
314+ bool isInitialShadowReceived = false ;
314315
315316 auto onGetShadowUpdatedAcceptedSubAck = [&](int ioErr) {
316317 if (ioErr != AWS_OP_SUCCESS)
@@ -347,6 +348,15 @@ int main(int argc, char *argv[])
347348 }
348349 if (response)
349350 {
351+ // If another client requested shadow for the same thing at the same time, this callback might be
352+ // triggered more than once. Ignore everything after first data arrived.
353+ if (isInitialShadowReceived)
354+ {
355+ fprintf (stderr, " Initial shadow is already set, ignore\n " );
356+ return ;
357+ }
358+ isInitialShadowReceived = true ;
359+
350360 fprintf (stdout, " Received shadow document.\n " );
351361 if (response->State && response->State ->Reported ->View ().ValueExists (cmdData.input_shadowProperty ))
352362 {
@@ -382,6 +392,15 @@ int main(int argc, char *argv[])
382392 fprintf (stderr, " Error on getting shadow document: %s.\n " , ErrorDebugString (ioErr));
383393 exit (-1 );
384394 }
395+ // If another client requested shadow for the same thing at the same time, this callback might be
396+ // triggered more than once. Ignore everything after first data arrived.
397+ if (isInitialShadowReceived)
398+ {
399+ fprintf (stderr, " Initial shadow is already set, ignore\n " );
400+ return ;
401+ }
402+ isInitialShadowReceived = true ;
403+
385404 fprintf (
386405 stdout,
387406 " Getting shadow document failed with message %s and code %d.\n " ,
0 commit comments