Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion whtree/modules/system/whlibs/internal/jobs.whlib
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ OBJECTTYPE MessageWaiter EXTEND __HS_INTERNAL_AsyncCallbackWaitHelperBase

UPDATE BOOLEAN FUNCTION HandleCallback(INTEGER handle, RECORD context)
{
RECORD rec := this->link->ReceiveMessage(DEFAULT DATETIME);
RECORD rec;
TRY
rec := this->link->ReceiveMessage(DEFAULT DATETIME);
CATCH(OBJECT e)
{
// autothrow and closed-link errors belong to the pending promise, not
// the unrelated caller pumping the event loop that delivered this read.
this->link->asyncmessagewaiter := DEFAULT OBJECT;
this->defer.reject(e);
RETURN TRUE;
}
IF (rec.status != "timeout" OR handle = -1)
{
IF (this->replyto != 0 AND rec.status = "ok" AND rec.replyto != this->replyto)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?wh
LOADLIB "wh::ipc.whlib";
LOADLIB "wh::datetime.whlib";
LOADLIB "wh::promise.whlib";
LOADLIB "mod::system/lib/testframework.whlib";

ASYNC MACRO TestAsyncIPCRejectsAutothrownExceptions()
{
STRING name := "webhare_testsuite:async-error-" || GenerateTemporaryIPCPortName();
OBJECT port := CreateGlobalIPCPort(name);
OBJECT client := ConnectToGlobalIPCPort(name);
OBJECT server := port->Accept(DEFAULT DATETIME);
client->autothrow := TRUE;
TRY
{
OBJECT request := client->AsyncDoRequest([value := 1]);
RECORD incoming := server->ReceiveMessage(MAX_DATETIME);
server->SendExceptionReply(NEW Exception("synthetic IPC rejection"), incoming.msgid);
VARIANT settled := AWAIT CreatePromiseAllSettled(OBJECT[request, CreateResolvedPromise(42)]);
TestEq("rejected", settled[0].status);
TestEq("synthetic IPC rejection", settled[0].reason->what);
TestEq("fulfilled", settled[1].status);
TestEq(42, settled[1].value);

// The failed read must release its registration so this link is reusable.
request := client->AsyncDoRequest([value := 2]);
incoming := server->ReceiveMessage(MAX_DATETIME);
server->SendReply([value := 2], incoming.msgid);
RECORD reply := AWAIT request;
TestEq(2, reply.msg.value);

request := client->AsyncReceiveMessage(MAX_DATETIME);
server->SendExceptionReply(NEW Exception("synthetic async receive rejection"), 0);
settled := AWAIT CreatePromiseAllSettled(OBJECT[request]);
TestEq("rejected", settled[0].status);
TestEq("synthetic async receive rejection", settled[0].reason->what);
}
FINALLY
{
client->Close();
server->Close();
port->Close();
}
}

RunTestframework([PTR TestAsyncIPCRejectsAutothrownExceptions]);
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<test script="test_witty.ts" />
<test script="test_wh_bridge_cli.sh" />
<test script="test_workers.ts" />
<test name="test_async_ipc" script="test_async_ipc.whscr" engine="native" />
<test script="test_unifiedcache.ts" />
<test script="test_modulesupport.ts" />
<test script="test_externals.ts" tags="external"/>
Expand Down
Loading