From 7434b46abd24bfde6c0ea276bd1a1528bc9b40f8 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Thu, 28 Nov 2024 13:00:27 +0530 Subject: [PATCH] Fix blocking webserver thread in tests --- .../listenerendpoint/WebServer.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/testobserve/native/src/main/java/org/ballerina/testobserve/listenerendpoint/WebServer.java b/testobserve/native/src/main/java/org/ballerina/testobserve/listenerendpoint/WebServer.java index ab2e209..bb56655 100644 --- a/testobserve/native/src/main/java/org/ballerina/testobserve/listenerendpoint/WebServer.java +++ b/testobserve/native/src/main/java/org/ballerina/testobserve/listenerendpoint/WebServer.java @@ -245,16 +245,18 @@ protected void channelRead0(ChannelHandlerContext ctx, Object o) { properties.put(ObservabilityConstants.KEY_OBSERVER_CONTEXT, observerContext); Utils.logInfo("Dispatching resource " + resourcePath); ObjectType objectType = (ObjectType) serviceObject.getOriginalType(); - try { - boolean isConcurrentSafe = objectType.isIsolated() && objectType.isIsolated(resourceFunctionName); - StrandMetadata metadata = new StrandMetadata(isConcurrentSafe, properties); - Object result = env.getRuntime().callMethod(serviceObject, resourceFunctionName, metadata, args); - handleResult(ctx, result, resourcePath); - } catch (BError error) { - handleError(ctx, error, resourcePath); - } catch (Throwable cause) { - handleError(ctx, ErrorCreator.createError(cause), resourcePath); - } + Thread.startVirtualThread(() -> { + try { + boolean isConcurrentSafe = objectType.isIsolated() && objectType.isIsolated(resourceFunctionName); + StrandMetadata metadata = new StrandMetadata(isConcurrentSafe, properties); + Object result = env.getRuntime().callMethod(serviceObject, resourceFunctionName, metadata, args); + handleResult(ctx, result, resourcePath); + } catch (BError error) { + handleError(ctx, error, resourcePath); + } catch (Throwable cause) { + handleError(ctx, ErrorCreator.createError(cause), resourcePath); + } + }); } @Override