@@ -340,6 +340,7 @@ int main(int argc, char *argv[])
340
340
std::promise<void > subscribeGetShadowRejectedCompletedPromise;
341
341
std::promise<void > onGetShadowRequestCompletedPromise;
342
342
std::promise<void > gotInitialShadowPromise;
343
+ bool isInitialShadowReceived = false ;
343
344
344
345
auto onGetShadowUpdatedAcceptedSubAck = [&](int ioErr) {
345
346
if (ioErr != AWS_OP_SUCCESS)
@@ -376,6 +377,15 @@ int main(int argc, char *argv[])
376
377
}
377
378
if (response)
378
379
{
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
+
379
389
fprintf (stdout, " Received shadow document.\n " );
380
390
if (response->State && response->State ->Reported ->View ().ValueExists (cmdData.input_shadowProperty ))
381
391
{
@@ -411,6 +421,15 @@ int main(int argc, char *argv[])
411
421
fprintf (stderr, " Error on getting shadow document: %s.\n " , ErrorDebugString (ioErr));
412
422
exit (-1 );
413
423
}
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
+
414
433
fprintf (
415
434
stdout,
416
435
" Getting shadow document failed with message %s and code %d.\n " ,
0 commit comments