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

[Bug]: 'gracefulStop()' method being called for the listeners which are not started #42534

Open
gabilang opened this issue Apr 10, 2024 · 0 comments
Assignees
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug

Comments

@gabilang
Copy link
Contributor

Description

$title

Steps to Reproduce

import ballerina/io;

listener DEF ep1 = new DEF("DEF");
listener ABC ep2 = new ABC("ABC");

public function main() returns error? {
    io:println("main called");
    // panic error("error from main");
}

function init() {
    io:println("initializing current module");
}

public class ABC {

    private string name = "";

    public function init(string name){
        self.name = name;
    }

    public function 'start() returns error? {
        io:println("listener start called - " + self.name);
        if (self.name == "ABC") {
            error sampleErr = error("panicked while starting listener attached with " + self.name);
            panic sampleErr;
        }
    }

    public function gracefulStop() returns error? {
        io:println("listener gracefulStop called - " + self.name);
        return ();
    }

    public function immediateStop() returns error? {
        io:println("listener immediateStop called - " + self.name);
        return ();
    }

    public function attach(service object {} s, string[]|string? name = ()) returns error? {
        io:println("listener attach called - " + self.name);
    }

    public function detach(service object {} s) returns error? {
        io:println("listener detach called - " + self.name);
    }
}


public class DEF {

    private string name = "";

    public function init(string name){
        self.name = name;
    }

    public function 'start() returns error? {
        io:println("listener start called - " + self.name);
        if (self.name == "DEF") {
            error sampleErr = error("panicked while starting listener attached with " + self.name);
            panic sampleErr;
        }
    }

    public function gracefulStop() returns error? {
        io:println("listener gracefulStop called - " + self.name);
        return ();
    }

    public function immediateStop() returns error? {
        io:println("listener immediateStop called - " + self.name);
        return ();
    }

    public function attach(service object {} s, string[]|string? name = ()) returns error? {
        io:println("listener attach called - " + self.name);
    }

    public function detach(service object {} s) returns error? {
        io:println("listener detach called - " + self.name);
    }
}

Output:

initializing current module
main called
listener start called - DEF
error: panicked while starting listener attached with DEF
        at DEF:start(Foo.bal:328)
listener gracefulStop called - DEF
listener gracefulStop called - ABC

Here the gracefulStop() method of listener bound with ABC has been called even without the 'start method of it get called.

Affected Version(s)

2201.8.x

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@gabilang gabilang added Type/Bug Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
None yet
Development

No branches or pull requests

1 participant