Azure / azure-iot-sdk-node

A Node.js SDK for connecting devices to Microsoft Azure IoT services
https://docs.microsoft.com/en-us/azure/iot-hub/
Other
262 stars 227 forks source link

Data Lake StorageV2+client.notifyBlobUploadStatus = Bad Request #1153

Closed 3TanE closed 1 year ago

3TanE commented 1 year ago

Description of the issue

In combination with a Data Lake StorageV2 client.notifyBlobUploadStatus responds with 400 Bad Request. This behavior happens every time. The upload itself how ever works like a charm. But since the upload is never confirmed by the device it is considered active until the TTL hit and further uploads are blocked.

Expected behavior

200 response since it is stated that the blob storage api is fully supported https://learn.microsoft.com/en-us/azure/storage/blobs/storage-feature-support-in-storage-accounts

Code sample exhibiting the issue

  1. Have a IOT Hub and at least one device setup
  2. Create and associate StorageV2 (general purpose v2) Container with the File upload from Iot-hub
  3. follow the guide/use the code from https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-file-upload

Console log of the issue

Blob Info : {
  correlationId: \<CorrelationID\>
  hostName: '\<StorageACCName\>.blob.core.windows.net',
  containerName: 'test01',
  blobName: '\<devicename\>/e45f0192da22_1665149221870_1-7-6_0002205.json',
  sasToken: 'XXXX'
}
Upload to IotHub for e45f0192da22_1665149221870_1-7-6_0002205.json successful
Partial Response :
<ref *2> IncomingMessage {
  _eventsCount: 3,
  _maxListeners: undefined,
  httpVersionMajor: 1,
  httpVersionMinor: 1,
  httpVersion: '1.1',
  complete: true,
  rawHeaders: [
    'content-length',
    '318',
    'connection',
    'close',
    'content-type',
    'application/json; charset=utf-8',
    'iothub-errorcode',
    'InvalidStorageEndpointOrBlob',
    'date',
    'Tue, 25 Oct 2022 07:42:46 GMT'
  ],
  url: '',
  method: null,
  statusCode: 400,
  statusMessage: 'Bad Request',
  _consuming: true,
  _dumped: false,
  req: <ref *3> ClientRequest {
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: null,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: <ref *1> TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: '\<hubname\>.azure-devices.net',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: '\<hubname\>.azure-devices.net',
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *3],
      ....
    },
    _header: 'POST /devices/\<devicename\>/files/notifications/\<CorrelationID\>?api-version=2021-04-12 HTTP/1.1\r\n' +
      'Host: \<hubname\>.azure-devices.net\r\n' +
      'User-Agent: azure-iot-device/1.18.1\r\n' +
      'Content-Type: application/json; charset=utf-8\r\n' +
      'Content-Length: 58\r\n' +
      'iothub-name: \<hubname\>\r\n' +
      'Authorization: SharedAccessSignature XXX' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/devices/\<devicename\>/files/notifications/\<CorrelationID\>?api-version=2021-04-12',
    _ended: true,
    res: [Circular *2],
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: '\<hubname\>.azure-devices.net',
    protocol: 'https:',
  },
}
Error: Bad Request
    at IncomingMessage.<anonymous> (XXXX/node_modules/azure-iot-http-base/dist/http.js:116:21)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

also related https://github.com/Azure/azure-sdk-for-js/issues/23587 if you need any further information i am happy to provide them

3TanE commented 1 year ago

Hey is there any update so far ?

vishnureddy17 commented 1 year ago

Sorry for the delay, @3TanE. I just gave it a go, and things seem to be working as expected on my end. Looking at the log you've sent, error sent from the service is "InvalidStorageEndpointOrBlob". It's likely that the IoT Hub is not configured with Azure Storage properly. Can you please double check that the Azure Storage container is correctly associated to the IoT Hub device?

The relevant section in the tutorial you sent is "Associate an Azure Storage account to IoT Hub"

3TanE commented 1 year ago

Hi @vishnureddy17 thanks for the heads up. I checked the configuration it did not seem to contain any faults and tested again and apparently it seems to work now. I can no longer recreate the problem. I guess smth in the backend has been fixxed.