Skip to content

Commit

Permalink
Merge pull request #41464 from HindujaB/fix-stop-handler
Browse files Browse the repository at this point in the history
Fix stop handler throwing CCE for type reference type
  • Loading branch information
warunalakshitha authored Oct 5, 2023
2 parents 33f2455 + 843d7e0 commit c79ac50
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.ballerina.runtime.internal.scheduling;

import io.ballerina.runtime.api.async.Callback;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BFunctionPointer;
import io.ballerina.runtime.api.values.BObject;
Expand Down Expand Up @@ -91,7 +92,8 @@ private synchronized void invokeStopHandlerFunction(Strand strand, Scheduler sch
BFunctionPointer<?, ?> bFunctionPointer = stopHandlerStack.pop();
StopHandlerCallback callback = new StopHandlerCallback(strand, scheduler);
final FutureValue future = scheduler.createFuture(strand, callback, null,
((BFunctionType) bFunctionPointer.getType()).retType, null, strand.getMetadata());
((BFunctionType) TypeUtils.getImpliedType(bFunctionPointer.getType())).retType, null,
strand.getMetadata());
scheduler.scheduleLocal(new Object[]{strand}, bFunctionPointer, strand, future);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public void testStopHandlerExecution() throws BallerinaTestException {
LogLeecher infoLeecher1 = new LogLeecher("Stopped stopHandlerFunc3");
LogLeecher infoLeecher2 = new LogLeecher("Stopped stopHandlerFunc2");
LogLeecher infoLeecher3 = new LogLeecher("Stopped stopHandlerFunc1");
LogLeecher infoLeecher4 = new LogLeecher("Stopped inlineStopHandler");
serverInstance.addLogLeecher(infoLeecher4);
serverInstance.addLogLeecher(infoLeecher1);
serverInstance.addLogLeecher(infoLeecher2);
serverInstance.addLogLeecher(infoLeecher3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ int count = 0;

function stopHandlerFunc1() returns error? {
incrementCount();
assertCount(5);
assertCount(6);
println("Stopped stopHandlerFunc1");
}

function stopHandlerFunc2() returns error? {
incrementCount();
assertCount(4);
assertCount(5);
println("Stopped stopHandlerFunc2");
}

function stopHandlerFunc3() returns error? {
incrementCount();
assertCount(3);
assertCount(4);
println("Stopped stopHandlerFunc3");
}

Expand All @@ -49,6 +49,12 @@ public function main() {
incrementCount();
assertCount(2);
runtime:onGracefulStop(stopHandlerFunc3);
runtime:StopHandler inlineStopHandler = function() returns error? {
incrementCount();
assertCount(3);
println("Stopped inlineStopHandler");
};
runtime:onGracefulStop(inlineStopHandler);
runtime:sleep(3);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public Object[] packageNameProvider() {
"invalid_values",
"async",
"utils",
"stop_handler",
"identifier_utils",
"environment"
};
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c79ac50

Please sign in to comment.