Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Grpc port #145

Closed
RichardBurns1982 opened this issue Apr 14, 2023 · 8 comments
Closed

Change Grpc port #145

RichardBurns1982 opened this issue Apr 14, 2023 · 8 comments
Labels
Enhancement New feature or request

Comments

@RichardBurns1982
Copy link

When running locally we have multiple functions running and we are using the extension AddDurableTaskClient so we can inject this to start orchestration functions:

services.AddDurableTaskClient(b =>
        {
            b.UseGrpc(grpcConfigure =>
            {
                grpcConfigure.Channel = GrpcChannel.ForAddress($"http://localhost:{PORT}");
            });
        });

How do we change the port so that one function can run GRPC on a different port to another function? When we try overriding the port we get connection errors from the GRPC framework.

This only affects us locally when developing as we can't have more than one function running at the same time but we would like to work around that limitation.

@jviau
Copy link
Member

jviau commented Apr 14, 2023

@RichardBurns1982 - are you using durable task standalone, or durable functions?

There has to be something on the other end of that port listening to this gRPC connection. In Durable Functions, you don't add the client yourself. Instead, you use the [DurableClient] DurableTaskClient client input binding to your function - the framework will handle providing a client which talks back to the functions host.

In DurableTask standalone, you need to know what port your gRPC sidecar is running on - but we haven't really made the sidecar support official yet. That is still to come.

@RichardBurns1982
Copy link
Author

@jviau Thanks for the response.

We are using durable functions.

We have multiple function projects, for example:

Function1
Function2
Function3

Each of these we are calling:

services.AddDurableTaskClient(b =>
        {
            b.UseGrpc();
        });

This allows us to take a dependency on DurableTaskClient in our classes from the DI container and this all works really well allowing us to start Orchestration Functions. As we are not changing any of the GRPC settings it is defaulting to port 4001. This is all fine if we are running a single function project locally or when deployed to Azure.

However, we have a need when developing locally to run multiple function projects at the same time, all of these are by default listening on port 4001. What we want to do is change it, when the HostingContext.IsDevelopment() is true and have:

Function1 - Port: 4001
Function2 - Port: 4002
Function3 - Port: 4003

Is this possible? The reason being we have an integration event framework which has subscriptions in each function project which triggers different orchestration functions in each project. The integration event handlers are resolved from the DI container with DurableTaskClient as a dependency.

@jviau
Copy link
Member

jviau commented Apr 17, 2023

DurableTaskClient is not meant to be used that way in Durable Functions. The port is supplied from the host extension as part of the input binding process, it is not known at startup.

See documentation here for examples on how to use the [DurableClient] input binding.

@RichardBurns1982
Copy link
Author

RichardBurns1982 commented Apr 17, 2023 via email

@jviau
Copy link
Member

jviau commented Apr 18, 2023

For durable functions in dotnet isolated, no there is no way to do this. You simply do not know what the gRPC port to bind to is, it is only supplied to the worker as part of input binding via the [DurableClient] attribute. This isn't to say we won't support to eventually; it totally depends on how/if things change in the functions extensibility model. In-process is different, there is no concept of talking from worker to host there, you are just accessing the backing durable task services directly - so they can be resolved via DI.

When you say "two functions locally", are you talking about two separate function apps entirely, or just two functions within the same project?

@jviau
Copy link
Member

jviau commented Apr 19, 2023

We've not observed any issues in production, what issues would you expect us to be seeing?

Want to clarify this. The functions extension code will first attempt to bind to 4001, so it may work for you most of the time. But when that port is reserved it will start trying to get random ports in the 30000 to 31000 range. This is when you will fail to bind to that client.

I understand your desire though, it would be nice to have the client in the DI container. I am currently exploring a feature which may enable this, I'll update this if that happens.

@jviau
Copy link
Member

jviau commented Nov 13, 2023

Closing this in favor of #154 - which will solve this issue.

@BYM-Henry
Copy link

@RichardBurns1982 did you ever find a workaround for this? We are currently experiencing the exact same issue, with getting an error when trying to run two function apps locally both injecting a DurableTaskClient into a service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants