@@ -340,6 +340,7 @@ int main(int argc, char *argv[])
340340 std::promise<void > subscribeGetShadowRejectedCompletedPromise;
341341 std::promise<void > onGetShadowRequestCompletedPromise;
342342 std::promise<void > gotInitialShadowPromise;
343+ bool isInitialShadowReceived = false ;
343344
344345 auto onGetShadowUpdatedAcceptedSubAck = [&](int ioErr) {
345346 if (ioErr != AWS_OP_SUCCESS)
@@ -376,6 +377,15 @@ int main(int argc, char *argv[])
376377 }
377378 if (response)
378379 {
380+ // If another client requested shadow for the same thing at the same time, this callback might be
381+ // triggered more than once. Ignore everything after first data arrived.
382+ if (isInitialShadowReceived)
383+ {
384+ fprintf (stderr, " Initial shadow is already set, ignore\n " );
385+ return ;
386+ }
387+ isInitialShadowReceived = true ;
388+
379389 fprintf (stdout, " Received shadow document.\n " );
380390 if (response->State && response->State ->Reported ->View ().ValueExists (cmdData.input_shadowProperty ))
381391 {
@@ -411,6 +421,15 @@ int main(int argc, char *argv[])
411421 fprintf (stderr, " Error on getting shadow document: %s.\n " , ErrorDebugString (ioErr));
412422 exit (-1 );
413423 }
424+ // If another client requested shadow for the same thing at the same time, this callback might be
425+ // triggered more than once. Ignore everything after first data arrived.
426+ if (isInitialShadowReceived)
427+ {
428+ fprintf (stderr, " Initial shadow is already set, ignore\n " );
429+ return ;
430+ }
431+ isInitialShadowReceived = true ;
432+
414433 fprintf (
415434 stdout,
416435 " Getting shadow document failed with message %s and code %d.\n " ,
0 commit comments