ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
137 stars 58 forks source link

Strands get blocked under high load during the concurrent access of the Pipe package #6812

Open Nuvindu opened 1 month ago

Nuvindu commented 1 month ago

Description: When using the xlibb/pipe module to produce and consume messages under high load, Ballerina strands get blocked, causing the code to hang and preventing it from completing execution.

Steps to reproduce:

  1. Run the following Ballerina service
import ballerina/http;
import ballerina/io;

import xlibb/pipe;

isolated class Hello {
    private final pipe:Pipe pipe = new (100000000);

    isolated function process() returns pipe:Error? {
        int i = 0;
        while i < 999999 {
            _ = check self.pipe.produce(string `Value ${i}`, -1);
            if i == 999998 {
                io:println("All values are published");
            }
            i += 1;
        }
    }

    isolated function consume() {
        int i = 0;
        while i < 999999 {
            string|error value = self.pipe.consume(-1);
            if i == 999998 {
                io:println("Last Element: ", value);
            }
            i += 1;
        }
    }
}

service / on new http:Listener(8080) {
    isolated resource function get test() returns http:Ok & readonly {
        Hello hello = new;
        _ = start hello.consume();
        _ = start hello.process();
        return http:OK;
    }
}
  1. Invoke the resource the resource method to execute consume() and produce() APIs
curl "http://localhost:8080/test"

Related Issues: https://github.com/ballerina-platform/ballerina-library/issues/6780

github-actions[bot] commented 1 month ago

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.