Function not returning when using amqplib package

Hi !

I have a function which takes a document as argument and publish to a channel using amqplib.

Here’s some simplified version

exports = async function (photo) {
    const { connect } = require("amqplib");

    try {
      console.log("Test: ", JSON.stringify({
                hostname: context.environment.values.amqp.hostname,
                port: context.environment.values.amqp.port,
                username: context.environment.values.amqp.username,
                password: context.values.get("amqpPasswordValue"),
                vhost: context.environment.values.amqp.vhost,
            }));

        // connecting to RabbitMQ server
        const connection = await connect(
            {
                hostname: context.environment.values.amqp.hostname,
                port: context.environment.values.amqp.port,
                username: context.environment.values.amqp.username,
                password: context.values.get("amqpPasswordValue"),
                vhost: context.environment.values.amqp.vhost,
            },
            { timeout: 30000 }
        );

        // closing connection
        await connection.close();
    } catch (err) {
        console.error("Error while sending AMQP message: ", err);
    }
};

If I comment the line below console.log it prints out the object just fine but if I add the connect part back the function timeout and nothing is printed not even the first console.log.
Weird thing is when I look at the RabbitMQ logs I see that the connection is opened and closed but the function doesn’t seem to stop.
I’ve tested this function using the console provided below the function editor in App Services UI (see below picture). But I was able to also reproduce this behavior when calling the function using a trigger.

When testing with the exact same code locally with node v18 it works fine.

At first I thought the problem my come from:

  • The library but I’m able to open and close a connection
  • usage of async/await but tried using promises and has same results
  • node version behind the app services or some other behind the scene thing ?

PS: when mentioning the function timeout I’m taking about the whole function not the timeout in connect which does return a different error if the value is very low (i.e 1)

Here’s what the function returns after like a whole minute (displayed in the result section in picture below)

> ran at 1669737017608
> took 
> error: 
Error: write after end

Any help would be greatly appreciated!