Azure / Azurite

A lightweight server clone of Azure Storage that simulates most of the commands supported by it with minimal dependencies
MIT License
1.8k stars 320 forks source link

Put Block List returns 500 Internal Server Error #1955

Open cloudtest-anon opened 1 year ago

cloudtest-anon commented 1 year ago

Which service(blob, file, queue, table) does this issue concern?

Azure Blob

Which version of the Azurite was used?

3.21.0

Where do you get Azurite? (npm, DockerHub, NuGet, Visual Studio Code Extension)

npm

What's the Node.js version?

14.18.1

What problem was encountered?

When performing a Put Block List operation, an unexpected 500 Internal Server Error was encountered. When investigated, it was found that the body of this request must be in XML format. Passing a body other than XML (e.g., JSON) leads to a 500. This was verified by replacing the JSON body with valid XML. The expected behavior should return a response "400 -- Bad Request" for the invalid body.

Request:

PUT /devstoreaccount1/container78/blob125?comp=blocklist HTTP/1.1\r\nAccept: application/json\r\nHost: 127.0.0.1:10000\r\nx-ms-version: 2021-12-02\r\nContent-Type: application/json\r\nAUTH_TOKEN\r\n\r\n{"BlockList": {"Committed": "first-base64-encoded-block-id","Uncommitted": "second-base64-encoded-block-id","Latest": "third-base64-encoded-block-id"}}

Response:

HTTP/1.1 500 Internal Server Error\r\nServer: Azurite-Blob/3.21.0\r\nDate: Tue, 07 Feb 2023 21:07:27 GMT\r\nConnection: keep-alive\r\nKeep-Alive: timeout=5\r\nContent-Length: 0\r\n\r\n

Steps to reproduce the issue?

The following REST calls should hit this case:

PUT /devstoreaccount1/container78?restype=container HTTP/1.1\r\nAccept: application/json\r\nHost: 127.0.0.1:10000\r\nx-ms-version: 2021-12-02\r\nAUTH_TOKEN\r\n\r\n
PUT /devstoreaccount1/container78/blob125?comp=blocklist HTTP/1.1\r\nAccept: application/json\r\nHost: 127.0.0.1:10000\r\nx-ms-version: 2021-12-02\r\nContent-Type: application/json\r\nAUTH_TOKEN\r\n\r\n{"BlockList": {"Committed": "first-base64-encoded-block-id","Uncommitted": "second-base64-encoded-block-id","Latest": "third-base64-encoded-block-id"}}

Debug log

2023-05-05T05:32:12.363Z 283af665-d775-46e0-96fa-80cdfb2a69cd info: DispatchMiddleware: Operation=BlockBlob_CommitBlockList
2023-05-05T05:32:12.363Z 283af665-d775-46e0-96fa-80cdfb2a69cd verbose: DeserializerMiddleware: Start deserializing...
2023-05-05T05:32:12.363Z 283af665-d775-46e0-96fa-80cdfb2a69cd debug: deserialize(): Raw request body string is (removed all empty characters) {"BlockList":{"Committed":"first-base64-encoded-block-id","Uncommitted":"second-base64-encoded-block-id","Latest":"third-base64-encoded-block-id"}}
2023-05-05T05:32:12.363Z 283af665-d775-46e0-96fa-80cdfb2a69cd info: HandlerMiddleware: DeserializedParameters={"options":{"metadata":{},"blobHTTPHeaders":{},"leaseAccessConditions":{},"cpkInfo":{},"modifiedAccessConditions":{}},"comp":"blocklist","version":"2021-12-02","blocks":{"committed":[],"uncommitted":[],"latest":[],"BlockList":{"Committed":"first-base64-encoded-block-id","Uncommitted":"second-base64-encoded-block-id","Latest":"third-base64-encoded-block-id"}},"body":"ReadableStream"}
2023-05-05T05:32:12.363Z 283af665-d775-46e0-96fa-80cdfb2a69cd error: ErrorMiddleware: Received an error, fill error information to HTTP response
2023-05-05T05:32:12.364Z 283af665-d775-46e0-96fa-80cdfb2a69cd error: ErrorMiddleware: ErrorName=Error ErrorMessage=Non-whitespace before first tag.
Line: 0
Column: 1
Char: { ErrorStack="Error: Non-whitespace before first tag.\nLine: 0\nColumn: 1\nChar: {\n    at error (/usr/local/lib/node_modules/azurite/node_modules/sax/lib/sax.js:651:10)\n    at strictFail (/usr/local/lib/node_modules/azurite/node_modules/sax/lib/sax.js:677:7)\n    at beginWhiteSpace (/usr/local/lib/node_modules/azurite/node_modules/sax/lib/sax.js:951:7)\n    at SAXParser.write (/usr/local/lib/node_modules/azurite/node_modules/sax/lib/sax.js:1006:11)\n    at Parser.exports.Parser.Parser.parseString (/usr/local/lib/node_modules/azurite/node_modules/xml2js/lib/parser.js:323:31)\n    at Parser.parseString (/usr/local/lib/node_modules/azurite/node_modules/xml2js/lib/parser.js:5:59)\n    at /usr/local/lib/node_modules/azurite/dist/src/blob/generated/utils/xml.js:28:19\n    at new Promise (<anonymous>)\n    at Object.parseXML (/usr/local/lib/node_modules/azurite/dist/src/blob/generated/utils/xml.js:27:12)\n    at BlockBlobHandler.commitBlockList (/usr/local/lib/node_modules/azurite/dist/src/blob/handlers/BlockBlobHandler.js:189:36)"
2023-05-05T05:32:12.364Z 283af665-d775-46e0-96fa-80cdfb2a69cd error: ErrorMiddleware: Set HTTP code: 500
2023-05-05T05:32:12.364Z 283af665-d775-46e0-96fa-80cdfb2a69cd info: EndMiddleware: End response. TotalTimeInMS=2 StatusCode=500 StatusMessage=undefined Headers={"server":"Azurite-Blob/3.21.0"}
blueww commented 1 year ago

@anna-mazhar Could you please give the whole debug log of the failed request? We would need it for the investigation.

cloudtest-anon commented 1 year ago

Sure.

debug.log