Azure / Azurite

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

Error when running azurite with host.docker.internal #2459

Closed Valkozaur closed 1 month ago

Valkozaur commented 2 months ago

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

Queue service

Which version of the Azurite was used?

3.31.0, 3.14.0

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

Dockerhub

What's the Node.js version?

What problem was encountered?

I am trying to run aspire, this is my code:

var storage = builder.AddAzureStorage("Storage");

if (builder.Environment.IsDevelopment())
{
    storage.RunAsEmulator(
        azuriteBuilder =>
        {
            azuriteBuilder
                .WithArgs(
                [
                    "docker-entrypoint.sh",
                    "azurite",
                    "-l",
                    "/data",
                    "--blobHost",
                    "0.0.0.0",
                    "--queueHost",
                    "0.0.0.0",
                    "--tableHost",
                    "0.0.0.0",
                    "--disableProductStyleUrl",
                    "--debug",
                    "/data/debug.log"
                ]);
        });
}

var blobs = storage.AddBlobs("blobs");
var queues = storage.AddQueues("queues");

builder.AddContainer("kernel-memory", "kernelmemory/service", "latest")
    .WithImageRegistry("docker.io")
    .WithBindMount("kernel.memory.appsettings.Development.json", "/app/appsettings.json")
    .WithEnvironment("KernelMemory__Services__AzureBlobs__ConnectionString", blobs)
    .WithEnvironment("KernelMemory__Services__AzureQueues__ConnectionString", queues)
    ;

The connection strings generated look like this:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;QueueEndpoint=http://host.docker.internal:61222/devstoreaccount1;

The issue is that every time that Kernel-Memory service tries to create a Queue It gets back a 400 bad request respose.

Kernel Memory connects to QueueClient using nuget package: Azure.Storage.Queues 12.19.1  

Steps to reproduce the issue?

-09-02T14:00:27.877Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 info: QueueStorageContextMiddleware: RequestMethod=PUT RequestURL=http://host.docker.internal/delete-generated-files RequestHeaders:{"host":"host.docker.internal:61572","x-ms-version":"2018-11-09","accept":"application/xml","x-ms-client-request-id":"3a95397e-18b5-4ce7-a40d-3ae9e763ded1","x-ms-return-client-request-id":"true","user-agent":"azsdk-net-Storage.Queues/12.18.0 (.NET 8.0.7; Alpine Linux v3.20)","x-ms-date":"Mon, 02 Sep 2024 14:00:22 GMT","authorization":"SharedKey devstoreaccount1:JOmKGBzEHz1pb5AQehQfdU7xpimHkEyXmu1GnVOrY8g=","content-length":"0"} ClientIP=192.168.127.1 Protocol=http HTTPVersion=1.1
2024-09-02T14:00:27.878Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 info: QueueStorageContextMiddleware: Account=delete-generated-files Queue=undefined Message=undefined MessageId=undefined
2024-09-02T14:00:27.879Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 verbose: DispatchMiddleware: Dispatching request...
2024-09-02T14:00:27.893Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 error: DispatchMiddleware: Incoming URL doesn't match any of swagger defined request patterns.
2024-09-02T14:00:27.895Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 error: ErrorMiddleware: Received a MiddlewareError, fill error information to HTTP response
2024-09-02T14:00:27.907Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 error: ErrorMiddleware: ErrorName=UnsupportedRequestError ErrorMessage=Incoming URL doesn't match any of swagger defined request patterns.  ErrorHTTPStatusCode=400 ErrorHTTPStatusMessage=undefined ErrorHTTPHeaders=undefined ErrorHTTPBody=undefined ErrorStack="UnsupportedRequestError: Incoming URL doesn't match any of swagger defined request patterns.\n    at dispatchMiddleware (/opt/azurite/dist/src/queue/generated/middleware/dispatch.middleware.js:41:30)\n    at /opt/azurite/dist/src/queue/generated/ExpressMiddlewareFactory.js:49:47\n    at Layer.handle [as handle_request] (/opt/azurite/node_modules/express/lib/router/layer.js:95:5)\n    at trim_prefix (/opt/azurite/node_modules/express/lib/router/index.js:328:13)\n    at /opt/azurite/node_modules/express/lib/router/index.js:286:9\n    at Function.process_params (/opt/azurite/node_modules/express/lib/router/index.js:346:12)\n    at next (/opt/azurite/node_modules/express/lib/router/index.js:280:10)\n    at queueStorageContextMiddleware (/opt/azurite/dist/src/queue/middlewares/queueStorageContext.middleware.js:97:5)\n    at /opt/azurite/dist/src/queue/middlewares/queueStorageContext.middleware.js:15:16\n    at Layer.handle [as handle_request] (/opt/azurite/node_modules/express/lib/router/layer.js:95:5)"
2024-09-02T14:00:27.907Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 error: ErrorMiddleware: Set HTTP code: 400
2024-09-02T14:00:27.907Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 error: ErrorMiddleware: Set HTTP body: undefined
2024-09-02T14:00:27.908Z 6419cfd6-b51c-4dd7-98c0-32262af4fca5 info: EndMiddleware: End response. TotalTimeInMS=32 StatusCode=400 StatusMessage=undefined Headers={"server":"Azurite-Queue/3.31.0"}

Have you found a mitigation/solution?

No

blueww commented 1 month ago

@EmmaZhu Would you please help to look?

Besides that, it looks the Uri in the debug log is not right "http://host.docker.internal/delete-generated-files", the Uri not include storage account name. It should looks like "http://host.docker.internal/[AccountName]/[QueueName]"

Valkozaur commented 1 month ago

Hello @blueww

I have figured out that this problem is not coming from the azurite emulator, but from QueueClient in the .net azure-sdk.

Currently I have not opened an issue there, but I will and link it afterwards.

blueww commented 1 month ago

@Valkozaur

I will close this issue as it's not an Azurite issue but a client issue. Feel free to contact us if need any further assistance on Azurite.