ballerina-platform / ballerina-library

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

Getting NoSuchElementException in Pipe #6780

Open xlight05 opened 3 months ago

xlight05 commented 3 months ago

Description: $Subject

Getting this intermittently.

error: java.util.NoSuchElementException
        at xlibb:consume(pipe.bal:56)
           wso2.ballerina_copilot.0.ServerResponseGen:next(claude.bal:205)
           ballerina.lang.stream.0:next(stream.bal:77)
           ballerina.http.2.SseEventToByteStreamGenerator:next(sse_to_bytes_stream_generator.bal:18)
[2024-07-19 19:08:06,563] SEVERE {b7a.log.crash} - java.util.NoSuchElementException

Steps to reproduce: The following sample seems to reproduce this consistently. Not sure if its the same issue that I faced tho ;(

import ballerina/http;
import xlibb/pipe;
import ballerina/io;

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

    function process() {
        foreach int i in 0...999999 {
            error? x = self.pipe.produce("Hello from worker A", 80);
            if x is error {
                io:println("Error: ", x);
            }
        }
    }

    function consume() {
        foreach int i in 0...999999 {
            string|error value = self.pipe.consume(80);
            if value is error {
                io:println("Error: ", value);
            }
        }
    }
}

service / on new http:Listener(8080) {
    resource function get test() returns http:Ok & readonly {
        Hello hello = new;
        _ = start hello.process();
        _ = start hello.consume();
        return http:OK;
    }
}

Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):