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

Many connections opened for IModel #148

Closed
basilfx opened this issue Jan 20, 2021 · 2 comments · Fixed by #149
Closed

Many connections opened for IModel #148

basilfx opened this issue Jan 20, 2021 · 2 comments · Fixed by #149
Assignees

Comments

@basilfx
Copy link

basilfx commented Jan 20, 2021

I'm using the code below, based on the examples in the wiki. It is an Azure Function V3 function, using .NET Core 3.1. I'm running this locally.

Whenever I run this, I notice that I have a lot of open connections, up to a point where I'm running out of connections and the application stalls. The RabbitMQ Management Interface shows all these connections as well, and they all disappear when I kill the application. To my understanding, channels are multiplexed on a single connection, so I would assume a single connection, instead of a connection per function invocation. Therefore, I think this is a bug.

As a 'work-around', I now inject a my own IConnection in my function class, then use using (var channel = connection.CreateModel() { .. } which works as expected. I also notice that it is faster: I was managing 5 msg/sec, now 25 msg/sec.

Code:

[FunctionName("FunctionName")]
public async Task RunAsync(
    [RabbitMQTrigger(
        "QueueName",
        ConnectionStringSetting = "ConnectionString")]
    BasicDeliverEventArgs message,
    [RabbitMQ(ConnectionStringSetting = "ConnectionString")]
    IModel channel)
{
    // Some processing of the message here.
    // ...

    // Publish updates to an exchange
    var batch = channel.CreateBasicPublishBatch();

    foreach (var update in updates.Values)
    {
        var (body, properties) = MessagingHelper.ToMessage(update, message);

        batch.Add(
            exchange: "ExchangeName",
            routingKey: "",
            mandatory: false,
            properties: properties,
            body: body);
    }

    batch.Publish();

    // Doesn't help
    // channel.Close()
}
@Socolin
Copy link
Contributor

Socolin commented Feb 2, 2021

I confirm the problem I just experimented this after deploying a new version of our app in production.

This is blocking our deployment, could you please fix this soon ?

@jeffhollan This project seems dead again can we expect a fix soon ? or should I found another way to fix this on my own ?

@yojagad yojagad added this to the Functions Sprint 95 milestone Feb 4, 2021
@yojagad yojagad self-assigned this Feb 4, 2021
@yojagad
Copy link
Contributor

yojagad commented Feb 4, 2021

Thanks for reporting. I'll take a look at this and possibly send a fix

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

Successfully merging a pull request may close this issue.

3 participants