Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
13 changes: 10 additions & 3 deletions mcs/class/corlib/System.Runtime.Remoting/RemotingServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,9 @@ internal static byte[] SerializeCallData (object obj)

if (obj == null) return null;
MemoryStream ms = new MemoryStream ();
_serializationFormatter.Serialize (ms, obj);
lock (_serializationFormatter) {
_serializationFormatter.Serialize (ms, obj);
}
return ms.ToArray ();
}

Expand All @@ -791,7 +793,10 @@ internal static object DeserializeCallData (byte[] array)
if (array == null) return null;

MemoryStream ms = new MemoryStream (array);
object obj = _deserializationFormatter.Deserialize (ms);
object obj;
lock (_deserializationFormatter) {
obj = _deserializationFormatter.Deserialize (ms);
}

if (obj is CACD) {
CACD cad = (CACD) obj;
Expand All @@ -813,7 +818,9 @@ internal static byte[] SerializeExceptionData (Exception ex)
/* empty - we're only interested in the protected block */
} finally {
MemoryStream ms = new MemoryStream ();
_serializationFormatter.Serialize (ms, ex);
lock (_serializationFormatter) {
_serializationFormatter.Serialize (ms, ex);
}
result = ms.ToArray ();
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// MonoTests.System.Runtime.Remoting.RemotingServicesTest.cs
//
// Author: Alexis Christoforides ([email protected])
//
// 2018 (C) Copyright, Novell, Inc.
//

using System;
using System.Reflection;
using System.Threading.Tasks;
using NUnit.Framework;

namespace MonoTests.System.Runtime.Remoting
{
[TestFixture]
public class RemotingServicesTest
{
public class AppDomainObject : MarshalByRefObject
{
public void Init(CrossDomainSerializedObject applicationDependencies) // racy exception here
{

}
}

public class CrossDomainSerializedObject : MarshalByRefObject
{
}
private static CrossDomainSerializedObject crossDomainSerializedObject;

private static void AppDomainWithRemotingSerialization(Assembly assembly, string name)
{
var appDomain = AppDomain.CreateDomain(name);
var appDomainObject = (AppDomainObject)appDomain.CreateInstanceAndUnwrap(assembly.GetName().Name, typeof(AppDomainObject).FullName);
appDomainObject.Init(crossDomainSerializedObject);
}

[Test]
public void Bug46473 () // concurrent serialization/deserialization
{
bool success = true;
crossDomainSerializedObject = new CrossDomainSerializedObject();
Task[] tasks = new Task [20];
for (int i = 0; i < tasks.Length; i++)
{
var assembly = Assembly.GetAssembly(typeof(AppDomainObject));
var name = "AppDomainWithCall" + i;
tasks [i] = Task.Factory.StartNew(() => AppDomainWithRemotingSerialization(assembly, name));
}
try {
Task.WaitAll (tasks);
} catch (AggregateException e) {
success = false;
Console.WriteLine ($"{e}, {e.InnerException}");
}
Assert.IsTrue (success, "Bug46473 (exception during remoting call)");
}
}
}
1 change: 1 addition & 0 deletions mcs/class/corlib/corlib_test.dll.sources
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ System.Runtime.InteropServices/StructLayoutAttributeTest.cs
System.Runtime.Remoting/ContextTest.cs
System.Runtime.Remoting/SoapServicesTest.cs
System.Runtime.Remoting/SynchronizationAttributeTest.cs
System.Runtime.Remoting/RemotingServicesTest.cs
System.Runtime.Remoting.Channels/ChannelServicesTest.cs
System.Runtime.Remoting.Contexts/SynchronizationAttributeTest.cs
System.Runtime.Remoting.Messaging/CallContextTest.cs
Expand Down
1 change: 1 addition & 0 deletions mcs/class/corlib/monotouch_corlib_test.dll.exclude.sources
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ System.Runtime.Remoting/ContextTest.cs
System.Runtime.Remoting/RemotingConfigurationTest.cs
System.Runtime.Remoting/SoapServicesTest.cs
System.Runtime.Remoting/SynchronizationAttributeTest.cs
System.Runtime.Remoting/RemotingServicesTest.cs
System.Security.AccessControl/AuthorizationRuleTest.cs
System.Security.AccessControl/CommonAceTest.cs
System.Security.AccessControl/CommonAclTest.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ System.Runtime.Remoting/ContextTest.cs
System.Runtime.Remoting/RemotingConfigurationTest.cs
System.Runtime.Remoting/SoapServicesTest.cs
System.Runtime.Remoting/SynchronizationAttributeTest.cs
System.Runtime.Remoting/RemotingServicesTest.cs
System.Runtime.Remoting.Channels/ChannelServicesTest.cs
System.Runtime.Remoting.Contexts/SynchronizationAttributeTest.cs
System.Runtime.Remoting.Messaging/CallContextTest.cs
Expand Down
1 change: 1 addition & 0 deletions mcs/class/corlib/wasm_corlib_test.dll.exclude.sources
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ System.Runtime.Remoting/ContextTest.cs
System.Runtime.Remoting/RemotingConfigurationTest.cs
System.Runtime.Remoting/SoapServicesTest.cs
System.Runtime.Remoting/SynchronizationAttributeTest.cs
System.Runtime.Remoting/RemotingServicesTest.cs
System.Runtime.Remoting.Channels/ChannelServicesTest.cs
System.Runtime.Remoting.Contexts/SynchronizationAttributeTest.cs
System.Runtime.Remoting.Messaging/CallContextTest.cs
Expand Down