Skip to content

Commit

Permalink
Fix blocking webserver thread in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Nov 28, 2024
1 parent a4bc29a commit 7434b46
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7434b46

Please sign in to comment.