Too Many Devices Error

Jerry Naidoo 30 Reputation points
2023-10-31T09:24:01.87+00:00

https://github.com/Azure/azure-iot-sdk-java/blob/main/iothub/device/iot-device-samples/file-upload-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/FileUploadSimpleSample.java

Hello,

I am trying to use the above example. I can upload one file to my Azure Blob container fine. Then I start a loop to upload 400+ files. After about 24 files, I get the error "Failed to get the file upload SAS URI" , cause "TooManyDevicesException". I cannot find any documentation explaining why this error comes up.

I cannot seem to get rid of the error and have to wait till the next day and the code runs fine again until the 24th or so upload.

I am closing the client. I am send the "completefileuploadnotification" etc. I am testing the exact same code just to see if this code works vs my code. It seems the example code also has the same issue.

I tried reading the documentation but there is no clear explanation saying if you do this then you will get this particular error.

Any insights. solutions or Wiki I can read where the cause of this error is explained?

Thanks for any help provided. I will follow up on each lead and post what worked to resolve it.

Jerry

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,157 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
0 comments No comments
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,966 Reputation points
    2023-10-31T14:28:10.9333333+00:00

    Hi @Jerry Naidoo I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Error Message:

    Failed to get the file upload SAS URI" , cause "TooManyDevicesException"

    Issue:

    Trying to upload 400+ plus files using the file upload sample results in TooManyDevicesException and fails to upload files.

    Solution:

    Changing the structure of the file upload code helped resolve the issue.

    Here is the initial code structure.

    //pseudo code
    Start upload loop
    	new client
    	open client
    	uploadfile
    	close client
    loop end
    

    Here is what worked to address the issue

    //pseudo code
    new client
    open client
    	Start upload loop
    	uploadfiles
    	loop end
    close client
    

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    I hope this helps!

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.

    Kindly note that, even though the issue is resolved with the changed code structure, the limitations mentioned by Sander above are still valid. If you try to use the same code concurrently and upload files onto a different device in your IoT Hub, you will still get throttled with respect to the limitations.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Sander van de Velde | MVP 31,211 Reputation points MVP
    2023-10-31T11:23:11.7533333+00:00

    Hello @Jerry Naidoo ,

    welcome to this moderated Azure community forum.

    There are some limitations to the IoT Hub file upload feature:

    1.67 file upload initiations/sec/unit (100/min/unit) for the S1

    and

    10 concurrent file uploads per device

    Can you check if you reach any of these limitations in your test?


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    1 person found this answer helpful.

  2. Jerry Naidoo 30 Reputation points
    2023-10-31T11:33:48.81+00:00

    Hello,

    I continued to debug and finally I found my issue.

    My code was structured as like this:

    //pseudo code
    Start upload loop
    	new client
    	open client
    	uploadfile
    	close client
    loop end
    

    I then changed it to this structure and I no longer get the toomanydevicesexception

    //pseudo code
    new client
    open client
    	Start upload loop
    	uploadfiles
    	loop end
    close client
    

    I followed my structure basing my experiences on USB/SERIAL ports. We never keep the connection open longer than needed but I guess for this type of operation it needs a one time open and one time close.

    Hope this helps someone one day.

    Regards

    Jerry

    1 person found this answer helpful.
    0 comments No comments