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

[browser][MT] dedicated io thread #99422

Merged
merged 9 commits into from
Mar 14, 2024
Merged
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
3 changes: 3 additions & 0 deletions eng/testing/WasmRunnerTemplate.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ if /I [%XHARNESS_COMMAND%] == [test] (
if [%BROWSER_PATH%] == [] if not [%HELIX_CORRELATION_PAYLOAD%] == [] (
set "BROWSER_PATH=--browser-path^=%HELIX_CORRELATION_PAYLOAD%\chrome-win\chrome.exe"
)
if [%JS_ENGINE_ARGS%] == [] (
set "JS_ENGINE_ARGS=--browser-arg^=--js-flags^=--stack-trace-limit^=1000"
)
)

if [%XHARNESS_ARGS%] == [] (
Expand Down
4 changes: 4 additions & 0 deletions eng/testing/WasmRunnerTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then
fi
fi
fi
else
if [[ -z "$JS_ENGINE_ARGS" ]]; then
JS_ENGINE_ARGS="--browser-arg=--js-flags=--stack-trace-limit=1000"
fi
fi

if [[ -z "$XHARNESS_ARGS" ]]; then
Expand Down
1 change: 0 additions & 1 deletion eng/testing/tests.browser.targets
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
<_AppArgs Condition="'$(IsFunctionalTest)' != 'true' and '$(WasmMainAssemblyFileName)' != ''">--run $(WasmMainAssemblyFileName)</_AppArgs>
<_AppArgs Condition="'$(IsFunctionalTest)' == 'true'">--run $(AssemblyName).dll</_AppArgs>

<_XUnitBackgroundExec Condition="'$(_XUnitBackgroundExec)' == '' and '$(WasmEnableThreads)' == 'true'">true</_XUnitBackgroundExec>
<WasmTestAppArgs Condition="'$(_XUnitBackgroundExec)' == 'true'">$(WasmTestAppArgs) -backgroundExec</WasmTestAppArgs>
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
<WasmXHarnessMonoArgs Condition="'$(_XUnitBackgroundExec)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=IsWasmBackgroundExec=true</WasmXHarnessMonoArgs>
<_AppArgs Condition="'$(WasmTestAppArgs)' != ''">$(_AppArgs) $(WasmTestAppArgs)</_AppArgs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static async Task CancellationHelper(Task promise, CancellationToken canc
}
}, (promise, jsController)))
{
await promise.ConfigureAwait(true);
await promise.ConfigureAwait(false);
}
}
catch (OperationCanceledException oce) when (cancellationToken.IsCancellationRequested)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void v1(string xmlFile, string xsdFile, bool allowXmlAttributes, int expe
if (xsdFile != null)
xss.Add(null, Path.Combine(testData, xsdFile));

XmlReader vr = CreateReader(Path.Combine(testData, xmlFile), xss, allowXmlAttributes);
using XmlReader vr = CreateReader(Path.Combine(testData, xmlFile), xss, allowXmlAttributes);
while (vr.Read()) ;

Assert.Equal(warningCount, expectedWarningCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void v1(object param0, object param1, object param2, int[] expectedErrorL
xss.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
xss.Add(null, Path.Combine(testData, xsdFile));

XmlReader vr = CreateReader(Path.Combine(testData, xmlFile), xss, false);
using XmlReader vr = CreateReader(Path.Combine(testData, xmlFile), xss, false);
while (vr.Read()) ;

CError.Compare(errorCount, expectedErrorCount, "Error Count mismatch");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void v2()
XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
settings.Schemas.Add(ss);
XmlReader vr = XmlReader.Create(Path.Combine(TestData._Root, "bug115049.xml"), settings);
using XmlReader vr = XmlReader.Create(Path.Combine(TestData._Root, "bug115049.xml"), settings);
while (vr.Read()) ;
CError.Compare(errorCount, 1, "Error Count mismatch!");
return;
Expand All @@ -108,7 +108,7 @@ public void v4()
XmlSchemaValidationFlags.ProcessSchemaLocation |
XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
XmlReader vr = XmlReader.Create(new StringReader(xml), settings, (string)null);
using XmlReader vr = XmlReader.Create(new StringReader(xml), settings, (string)null);
while (vr.Read()) ;
CError.Compare(errorCount, 0, "Error Count mismatch!");
CError.Compare(warningCount, 1, "Warning Count mismatch!");
Expand Down Expand Up @@ -531,7 +531,7 @@ public void v106()
#pragma warning disable 0618
settings.ProhibitDtd = false;
#pragma warning restore 0618
XmlReader r = XmlReader.Create(Path.Combine(TestData._Root, "XMLSchema.xsd"), settings);
using XmlReader r = XmlReader.Create(Path.Combine(TestData._Root, "XMLSchema.xsd"), settings);
ss1.Add(null, r);
ss1.Compile();

Expand Down Expand Up @@ -568,7 +568,7 @@ public void v107()
settings.Schemas.Add(schemaSet);
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
settings.ValidationType = ValidationType.Schema;
XmlReader vr = XmlReader.Create(new StringReader(strXml), settings);
using XmlReader vr = XmlReader.Create(new StringReader(strXml), settings);

while (vr.Read()) ;

Expand Down Expand Up @@ -742,7 +742,7 @@ public void v112()
XmlSchema mainSchema = set.Add(null, Path.Combine(TestData._Root, "bug382035a.xsd"));
set.Compile();

XmlReader r = XmlReader.Create(Path.Combine(TestData._Root, "bug382035a1.xsd"));
using XmlReader r = XmlReader.Create(Path.Combine(TestData._Root, "bug382035a1.xsd"));
XmlSchema reParsedInclude = XmlSchema.Read(r, new ValidationEventHandler(ValidationCallback));

((XmlSchemaExternal)mainSchema.Includes[0]).Schema = reParsedInclude;
Expand All @@ -766,7 +766,7 @@ public void v113()
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
settings.ValidationType = ValidationType.Schema;
XmlReader vr = XmlReader.Create(new StringReader(strXml), settings);
using XmlReader vr = XmlReader.Create(new StringReader(strXml), settings);

while (vr.Read()) ;

Expand Down Expand Up @@ -1056,7 +1056,7 @@ public void Dev10_40509()
string xsd = Path.Combine(TestData._Root, "bug511217.xsd");
XmlSchemaSet s = new XmlSchemaSet();
s.XmlResolver = new XmlUrlResolver();
XmlReader r = XmlReader.Create(xsd);
using XmlReader r = XmlReader.Create(xsd);
s.Add(null, r);
s.Compile();
XmlReaderSettings rs = new XmlReaderSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void TestSchemaCompile(string fileName, bool negative)
Assert.True(negative, args.Message);
numevents++;
};
XmlReader r = XmlReader.Create(xsd);
using XmlReader r = XmlReader.Create(xsd);
s.Add(null, r);
s.Compile();
Assert.False(negative && numevents != 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void v2()
Initialize();
XmlSchemaSet xss = new XmlSchemaSet();
xss.ValidationEventHandler += ValidationCallback;
XmlReader r = CreateReader(Path.Combine(TestData._Root, "bug356711_a.xsd"));
using XmlReader r = CreateReader(Path.Combine(TestData._Root, "bug356711_a.xsd"));
try
{
xss.Add(null, r);
Expand Down Expand Up @@ -190,7 +190,7 @@ public void v4()
XmlSchemaSet xss = new XmlSchemaSet();
xss.XmlResolver = new XmlUrlResolver();
xss.ValidationEventHandler += ValidationCallback;
XmlReader r = CreateReader(Path.Combine(TestData._Root, "bug356711.xsd"));
using XmlReader r = CreateReader(Path.Combine(TestData._Root, "bug356711.xsd"));
try
{
xss.Add(null, r);
Expand Down Expand Up @@ -314,7 +314,7 @@ public void v10(object param0)
xss.XmlResolver = new XmlUrlResolver();
xss.ValidationEventHandler += ValidationCallback;

XmlReader r = CreateReader(Path.Combine(TestData._Root, param0.ToString()), false);
using XmlReader r = CreateReader(Path.Combine(TestData._Root, param0.ToString()), false);
try
{
xss.Add(null, r);
Expand Down Expand Up @@ -363,8 +363,8 @@ public void v12(object param0)
XmlSchemaSet xss = new XmlSchemaSet();
xss.ValidationEventHandler += ValidationCallback;

XmlReader r = CreateReader(Path.Combine(TestData._Root, param0.ToString()), false);
XmlReader r2 = CreateReader(r, true);
using XmlReader r = CreateReader(Path.Combine(TestData._Root, param0.ToString()), false);
using XmlReader r2 = CreateReader(r, true);
try
{
xss.Add(null, r2);
Expand All @@ -387,8 +387,8 @@ public void v13(object param0)
xss.XmlResolver = new XmlUrlResolver();
xss.ValidationEventHandler += ValidationCallback;

XmlReader r = CreateReader(Path.Combine(TestData._Root, param0.ToString()), false);
XmlReader r2 = CreateReader(r, true);
using XmlReader r = CreateReader(Path.Combine(TestData._Root, param0.ToString()), false);
using XmlReader r2 = CreateReader(r, true);

try
{
Expand All @@ -413,7 +413,7 @@ public void v14()
xss.XmlResolver = new XmlUrlResolver();
xss.ValidationEventHandler += ValidationCallback;

XmlReader r = CreateReader(Path.Combine(TestData._Root, "bug356711.xsd"), false);
using XmlReader r = CreateReader(Path.Combine(TestData._Root, "bug356711.xsd"), false);

try
{
Expand All @@ -437,8 +437,8 @@ public void v15()
XmlSchemaSet xss = new XmlSchemaSet();
xss.ValidationEventHandler += ValidationCallback;

XmlReader r1 = CreateReader(Path.Combine(TestData._Root, "bug356711_a.xsd"));
XmlReader r2 = CreateReader(Path.Combine(TestData._Root, "bug356711_b.xsd"), false);
using XmlReader r1 = CreateReader(Path.Combine(TestData._Root, "bug356711_a.xsd"));
using XmlReader r2 = CreateReader(Path.Combine(TestData._Root, "bug356711_b.xsd"), false);

try
{
Expand Down Expand Up @@ -482,7 +482,7 @@ public void v20(object param0)

try
{
XmlReader reader = CreateReader(Path.Combine(TestData._Root, param0.ToString()), xss, true);
using XmlReader reader = CreateReader(Path.Combine(TestData._Root, param0.ToString()), xss, true);
while (reader.Read()) ;
}
catch (XmlException)
Expand Down Expand Up @@ -539,7 +539,7 @@ public void v22(object param0)

try
{
XmlReader reader = CreateReader(Path.Combine(TestData._Root, param0.ToString()), xss, false);
using XmlReader reader = CreateReader(Path.Combine(TestData._Root, param0.ToString()), xss, false);
while (reader.Read()) ;
}
catch (XmlException)
Expand All @@ -561,8 +561,8 @@ public void v23()

try
{
XmlReader r1 = CreateReader(Path.Combine(TestData._Root, "bug356711_1.xml"), true);
XmlReader r2 = CreateReader(r1, xss, false);
using XmlReader r1 = CreateReader(Path.Combine(TestData._Root, "bug356711_1.xml"), true);
using XmlReader r2 = CreateReader(r1, xss, false);
while (r2.Read()) ;
}
catch (XmlException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public void v51(object param0, object param1, object param2, object param3)
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
settings.ValidationType = ValidationType.Schema;
settings.Schemas = set;
XmlReader reader = XmlReader.Create(xmlFile, settings);
using XmlReader reader = XmlReader.Create(xmlFile, settings);
while (reader.Read()) { }

CError.Compare(bWarningCallback, false, "Warning count mismatch");
Expand All @@ -581,8 +581,8 @@ public void v51(object param0, object param1, object param2, object param3)
bErrorCallback = false;
_output.WriteLine("Second validation ***************");
settings.Schemas = set;
reader = XmlReader.Create(xmlFile, settings);
while (reader.Read()) { }
using XmlReader reader2 = XmlReader.Create(xmlFile, settings);
while (reader2.Read()) { }

CError.Compare(bWarningCallback, false, "Warning count mismatch");
CError.Compare(bErrorCallback, false, "Error count mismatch");
Expand All @@ -606,8 +606,8 @@ public void v51(object param0, object param1, object param2, object param3)

_output.WriteLine("Third validation, Expecting errors ***************");
settings.Schemas = set;
reader = XmlReader.Create(xmlFile, settings);
while (reader.Read()) { }
using XmlReader reader3 = XmlReader.Create(xmlFile, settings);
while (reader3.Read()) { }

CError.Compare(bWarningCallback, false, "Warning count mismatch");
CError.Compare(bErrorCallback, true, "Error count mismatch");
Expand All @@ -623,7 +623,7 @@ public XmlSchema LoadSchema(string path, string baseuri)
_output.WriteLine("Correct uri: " + correctUri);
using (Stream s = new FileStream(Path.GetFullPath(path), FileMode.Open, FileAccess.Read, FileShare.Read, 1))
{
XmlReader r = XmlReader.Create(s, new XmlReaderSettings(), includeUri);
using XmlReader r = XmlReader.Create(s, new XmlReaderSettings(), includeUri);
_output.WriteLine("Reader uri: " + r.BaseURI);
using (r)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void XmlReaderAsALineInfoProvider()
XmlSchemaInfo info = new XmlSchemaInfo();

XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml(xmlSrc));
XmlReader r = XmlReader.Create(new StringReader(xmlSrc));
using XmlReader r = XmlReader.Create(new StringReader(xmlSrc));

val.LineInfoProvider = (r as IXmlLineInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ public void XSDValidationGeneratesInvalidError_1()
// TempDirectory path must end with a DirectorySeratorChar, otherwise it will throw in the Xml validation.
settings.Schemas.Add("mainschema", XmlReader.Create(new StringReader(xsd), null, EnsureTrailingSlash(tempDirectory.Path)));
settings.ValidationType = ValidationType.Schema;
XmlReader reader = XmlReader.Create(new StringReader(xml), settings);
using XmlReader reader = XmlReader.Create(new StringReader(xml), settings);
XmlDocument doc = new XmlDocument();

doc.Load(reader);
Expand All @@ -926,7 +926,7 @@ public void XSDValidationGeneratesInvalidError_2()
// TempDirectory path must end with a DirectorySeratorChar, otherwise it will throw in the Xml validation.
settings.Schemas.Add("mainschema", XmlReader.Create(new StringReader(xsd), null, EnsureTrailingSlash(tempDirectory.Path)));
settings.ValidationType = ValidationType.Schema;
XmlReader reader = XmlReader.Create(new StringReader(xml), settings);
using XmlReader reader = XmlReader.Create(new StringReader(xml), settings);
XmlDocument doc = new XmlDocument();

doc.Load(reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public static void ReleaseJSOwnedObjectByGCHandle(JSMarshalerArgument* arguments

try
{
// when we arrive here, we are on the thread which owns the proxies
var ctx = arg_exc.AssertCurrentThreadContext();
// when we arrive here, we are on the thread which owns the proxies or on IO thread
var ctx = arg_exc.ToManagedContext;
ctx.ReleaseJSOwnedObjectByGCHandle(arg_1.slot.GCHandle);
}
catch (Exception ex)
Expand All @@ -131,6 +131,11 @@ public static void CallDelegate(JSMarshalerArgument* arguments_buffer)
// we may need to consider how to solve blocking of the synchronous call
// see also https://github.com/dotnet/runtime/issues/76958#issuecomment-1921418290
arg_exc.AssertCurrentThreadContext();

if (JSProxyContext.ThreadBlockingMode == JSHostImplementation.JSThreadBlockingMode.AllowBlockingWaitInAsyncCode)
{
Thread.ThrowOnBlockingWaitOnJSInteropThread = true;
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

GCHandle callback_gc_handle = (GCHandle)arg_1.slot.GCHandle;
Expand All @@ -148,8 +153,16 @@ public static void CallDelegate(JSMarshalerArgument* arguments_buffer)
{
arg_exc.ToJS(ex);
}
#if FEATURE_WASM_MANAGED_THREADS
finally
{
if (JSProxyContext.ThreadBlockingMode == JSHostImplementation.JSThreadBlockingMode.AllowBlockingWaitInAsyncCode)
{
Thread.ThrowOnBlockingWaitOnJSInteropThread = false;
}
}
#endif
}

// the marshaled signature is: void CompleteTask<T>(GCHandle holder, Exception? exceptionResult, T? result)
public static void CompleteTask(JSMarshalerArgument* arguments_buffer)
{
Expand All @@ -161,8 +174,8 @@ public static void CompleteTask(JSMarshalerArgument* arguments_buffer)

try
{
// when we arrive here, we are on the thread which owns the proxies
var ctx = arg_exc.AssertCurrentThreadContext();
// when we arrive here, we are on the thread which owns the proxies or on IO thread
var ctx = arg_exc.ToManagedContext;
var holder = ctx.GetPromiseHolder(arg_1.slot.GCHandle);
JSHostImplementation.ToManagedCallback callback;

Expand Down Expand Up @@ -270,6 +283,10 @@ public static void BeforeSyncJSExport(JSMarshalerArgument* arguments_buffer)
{
var ctx = arg_exc.AssertCurrentThreadContext();
ctx.IsPendingSynchronousCall = true;
if (JSProxyContext.ThreadBlockingMode == JSHostImplementation.JSThreadBlockingMode.AllowBlockingWaitInAsyncCode)
{
Thread.ThrowOnBlockingWaitOnJSInteropThread = true;
}
}
catch (Exception ex)
{
Expand All @@ -288,6 +305,10 @@ public static void AfterSyncJSExport(JSMarshalerArgument* arguments_buffer)
{
var ctx = arg_exc.AssertCurrentThreadContext();
ctx.IsPendingSynchronousCall = false;
if (JSProxyContext.ThreadBlockingMode == JSHostImplementation.JSThreadBlockingMode.AllowBlockingWaitInAsyncCode)
{
Thread.ThrowOnBlockingWaitOnJSInteropThread = false;
}
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public enum MainThreadingMode : int
UIThread = 0,
// Running the managed main thread on dedicated WebWorker. Marshaling all JavaScript calls to and from the main thread.
DeputyThread = 1,
// TODO comments
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
DeputyAndIOThreads = 2,
}

// keep in sync with types\internal.ts
Expand All @@ -80,6 +82,8 @@ public enum JSThreadBlockingMode : int
// throw PlatformNotSupportedException if blocking .Wait is called on threads with JS interop, like JSWebWorker and Main thread.
// Avoids deadlocks (typically with pending JS promises on the same thread) by throwing exceptions.
NoBlockingWait = 0,
// TODO comments
AllowBlockingWaitInAsyncCode = 1,
// allow .Wait on all threads.
// Could cause deadlocks with blocking .Wait on a pending JS Task/Promise on the same thread or similar Task/Promise chain.
AllowBlockingWait = 100,
Expand Down
Loading
Loading