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

Ballerina hackathon use cases 7.1 and 7.2 are hanging when running the tests #5083

Open
ayeshLK opened this issue Jan 31, 2023 · 4 comments
Open

Comments

@ayeshLK
Copy link
Member

ayeshLK commented Jan 31, 2023

Description:

$subject

Distribution Version

  • Daily build for Ballerina SL update 4

Related to #3464

@ayeshLK
Copy link
Member Author

ayeshLK commented Sep 7, 2023

Tested this behavior with a simple ballerina project which has a simple HTTP service and a sub-module which has some async workers.

modules/submodule/submodule.bal

import ballerina/task;
import ballerina/time;
import ballerina/lang.runtime;
import ballerina/io;

function init() returns error? {
    startWorkers();
    task:Job job = object {
        public function execute() {
            startWorkers();
        }
    };
    _ = check task:scheduleOneTimeJob(job, time:utcToCivil(time:utcAddSeconds(time:utcNow(), 3)));
}

function startWorkers() {
    foreach string wk in ["w1", "w2", "w3"] {
        _ = start run(wk);
    }
}

isolated function run(string workerName) {
    while true {
        io:println("Running bal-worker", workerName);
        runtime:sleep(10);
    }
}

In the project tests I have imported this module.

tests/service_test.bal

import ballerina/io;
import ballerina/http;
import ballerina/test;
import bal_test.submodule as _;

// ballerina tests here

When I run the test for this project the tests are hanging. @warunalakshitha / @HindujaB cn you guys check this out ?

Sample code can be found here [1]

[1] - https://drive.google.com/file/d/1GY_vXG117vpm4HeL40TLyr94YEDZ515y/view?usp=sharing

@ayeshLK ayeshLK assigned warunalakshitha and HindujaB and unassigned ayeshLK Sep 7, 2023
@HindujaB
Copy link
Contributor

HindujaB commented Sep 7, 2023

This seems like a bug from runtime test execution.
The issue happens due to the workers are not getting terminated even though the tests are completed.
We need to terminate the workers when we stop the modules.

@HindujaB HindujaB transferred this issue from ballerina-platform/ballerina-library Sep 7, 2023
@HindujaB
Copy link
Contributor

HindujaB commented Sep 8, 2023

Tested this behavior with a simple ballerina project which has a simple HTTP service and a sub-module which has some async workers.

modules/submodule/submodule.bal

import ballerina/task;
import ballerina/time;
import ballerina/lang.runtime;
import ballerina/io;

function init() returns error? {
    startWorkers();
    task:Job job = object {
        public function execute() {
            startWorkers();
        }
    };
    _ = check task:scheduleOneTimeJob(job, time:utcToCivil(time:utcAddSeconds(time:utcNow(), 3)));
}

function startWorkers() {
    foreach string wk in ["w1", "w2", "w3"] {
        _ = start run(wk);
    }
}

isolated function run(string workerName) {
    while true {
        io:println("Running bal-worker", workerName);
        runtime:sleep(10);
    }
}

In the project tests I have imported this module.

tests/service_test.bal

import ballerina/io;
import ballerina/http;
import ballerina/test;
import bal_test.submodule as _;

// ballerina tests here

When I run the test for this project the tests are hanging. @warunalakshitha / @HindujaB cn you guys check this out ?

Sample code can be found here [1]

[1] - https://drive.google.com/file/d/1GY_vXG117vpm4HeL40TLyr94YEDZ515y/view?usp=sharing

This code seems to be working with 2201.8.0 test pack. This is related to a known bug ballerina-platform/ballerina-lang#41213. We fixed it for update 8.

So the issue could be from somewhere else.

@gabilang gabilang self-assigned this Oct 24, 2023
@gabilang
Copy link
Contributor

gabilang commented Oct 25, 2023

The following code hangs at runtime.

import ballerina/task;
import ballerina/time;
import ballerina/lang.runtime;

string[] & readonly arr = ["a", "b", "c"]; 

public function func() {
    foreach var val in arr {
        _ = @strand {thread: "any"} start foo(val);
    }
}

function foo(string s) returns error? {
    while true {
    }
}

function init() returns error? {
    task:Job job = object {
        public function execute() {
            func();
        }
    };
    _ = check task:scheduleOneTimeJob(job, time:utcToCivil(time:utcAddSeconds(time:utcNow(), 3)));

}

public function main() {
    runtime:sleep(3);
}

It has been observed from the Ballerina version 2201.4.0.
When we have task:scheduleOneTimeJob and runtime:sleep() altogether as above, runtime hangs. It seems this issue needs to be looked from the ballerina/task module.

Following is the strand-dump of above program

Ballerina Strand Dump [2023/10/26 10:21:49]
===========================================

Total strand group count        :       6
Total strand count              :       10
Active strand group count       :       3
Active strand count             :       3

group 4 [RUNNABLE]: [1]
        strand 8 [gabilan.test_proj.0:func][7] [RUNNABLE]

group 5 [RUNNABLE]: [1]
        strand 9 [gabilan.test_proj.0:func][7] [RUNNABLE]

group 6 [RUNNABLE]: [1]
        strand 10 [gabilan.test_proj.0:func][7] [RUNNABLE]

===========================================

All strand groups are in runnable state.

@gabilang gabilang transferred this issue from ballerina-platform/ballerina-lang Oct 25, 2023
@gabilang gabilang moved this from In Progress to BackLog in Ballerina Team Main Board Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: BackLog
Development

No branches or pull requests

5 participants