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

Copy Blob returns 500 Internal Server Error #1954

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 a PUT request is made to copy a blob from a given source that is not a URL, the request fails with a 500 Internal Server Error. The error response should instead be 400 (Bad Request) since a valid URL is expected as the source. Request:

PUT /devstoreaccount1/container78/blob378 HTTP/1.1\r\nAccept: application/json\r\nHost: 127.0.0.1:10000\r\nx-ms-copy-source: /devstoreaccount1/container78/blob347\r\nx-ms-version: 2021-12-02\r\nAUTH_TOKEN\r\n\r\n

Response:

HTTP/1.1 500 Internal Server Error\r\nServer: Azurite-Blob/3.21.0\r\nDate: Fri, 05 May 2023 01:18:17 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/blob378 HTTP/1.1\r\nAccept: application/json\r\nHost: 127.0.0.1:10000\r\nx-ms-copy-source: /devstoreaccount1/container78/blob347\r\nx-ms-version: 2021-12-02\r\nAUTH_TOKEN\r\n\r\n

Debug log

2023-05-04T23:28:19.067Z bea145d0-3097-4c05-bcac-673bcc6ae4b7 error: ErrorMiddleware: ErrorName=TypeError ErrorMessage=Invalid URL: /devstoreaccount1/container78/blob347 ErrorStack="TypeError [ERR_INVALID_URL]: Invalid URL: /devstoreaccount1/container78/blob347\n    at new NodeError (internal/errors.js:322:7)\n    at onParseError (internal/url.js:270:9)\n    at new URL (internal/url.js:346:5)\n    at BlobHandler.startCopyFromURL (/usr/local/lib/node_modules/azurite/dist/src/blob/handlers/BlobHandler.js:384:21)\n    at /usr/local/lib/node_modules/azurite/dist/src/blob/generated/middleware/HandlerMiddlewareFactory.js:58:18\n    at /usr/local/lib/node_modules/azurite/dist/src/blob/generated/ExpressMiddlewareFactory.js:78:63\n    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/azurite/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/usr/local/lib/node_modules/azurite/node_modules/express/lib/router/index.js:328:13)\n    at /usr/local/lib/node_modules/azurite/node_modules/express/lib/router/index.js:286:9\n    at Function.process_params (/usr/local/lib/node_modules/azurite/node_modules/express/lib/router/index.js:346:12)"
2023-05-04T23:28:19.067Z bea145d0-3097-4c05-bcac-673bcc6ae4b7 error: ErrorMiddleware: Set HTTP code: 500
2023-05-04T23:28:19.067Z bea145d0-3097-4c05-bcac-673bcc6ae4b7 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. And could you share which tool you use to send the rest API?

Besides that, it looks the "x-ms-copy-source" you input is not a valid Uri. Could you please input the whole source blob Uri and try again?

cloudtest-anon commented 1 year ago

Here is the log: debug.log The rest API call was made with a test framework written in python.

As previously mentioned, the server will only return a 500 Internal Server Error when the requested URI (x-ms-copy-source) is invalid, such as when a string like "blob22" or a relative URI, as shown in the example above, is used. If a valid absolute URI is used instead, the request will succeed without any issues.

blueww commented 1 year ago

@anna-mazhar

Thanks for the information! Would you please share is there any scenario on you side blocked for this issue? We need the info to evaluate the priority of the issue. Besides that, Could you share the error returned from product Azure in the case? The detail error should include error message, error code, status code ... (hide credential if any) So we can reference it to fix this issue.

cloudtest-anon commented 1 year ago

The response provided by Azurite was insufficient in assisting me with pinpointing the bug in my code until I switched to the actual cloud service.

Response from Azure Storage for the same request:

`'HTTP/1.1 400 The value for one of the HTTP headers is not in the correct format. .. \r\nx-ms-error-code: InvalidHeaderValue ..

InvalidHeaderValueThe value for one of the HTTP headers is not in the correct format.x-ms-copy-source/container78/blob347'`
blueww commented 1 year ago

@anna-mazhar

Thanks for the info! Will look into it and update you later.

However, as this issue won't block the normal scenario, and we are working on some new storage feature implementing in Azurite, this might won't be our priority recently.

Azurite welcome contribution! It would be great if you could raise a PR to fix it!