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

Misc fixes to C# locator discovery #3177

Merged
merged 2 commits into from
Nov 22, 2024
Merged
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
73 changes: 7 additions & 66 deletions csharp/src/IceLocatorDiscovery/PluginI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public Ice.Plugin
create(Ice.Communicator communicator, string name, string[] args) => new PluginI(communicator);
}

public interface Plugin : Ice.Plugin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this (obviously) internal API in C++ and Java, but not in C#, where it's internal unused code.

{
List<Ice.LocatorPrx> getLocators(string instanceName, int waitTime);
}

internal class Request : TaskCompletionSource<Ice.Object_Ice_invokeResult>
{
public Request(
Expand Down Expand Up @@ -206,48 +201,6 @@ public override Task<Ice.Object_Ice_invokeResult>
}
}

public List<Ice.LocatorPrx> getLocators(string instanceName, int waitTime)
{
//
// Clear locators from previous search.
//
lock (_mutex)
{
_locators.Clear();
}

//
// Find a locator
//
invoke(null, null);

//
// Wait for responses
//
if (instanceName.Length == 0)
{
Thread.Sleep(waitTime);
}
else
{
lock (_mutex)
{
while (!_locators.ContainsKey(instanceName) && _pending)
{
Monitor.Wait(_mutex, waitTime);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only Monitor.Wait(_mutex, ...), which means all the Monitor.Pulse(_mutex) elsewhere are useless.

}
}
}

//
// Return found locators
//
lock (_mutex)
{
return new List<Ice.LocatorPrx>(_locators.Values);
}
}

public void
foundLocator(Ice.LocatorPrx locator)
{
Expand Down Expand Up @@ -363,7 +316,6 @@ public void
if (_pendingRequests.Count == 0)
{
_locators[locator.ice_getIdentity().category] = l;
Monitor.Pulse(_mutex);
}
else
{
Expand Down Expand Up @@ -427,7 +379,7 @@ public void

foreach (var l in _lookups)
{
_ = preformFindLocatorAsync(l.Key, l.Value);
_ = performFindLocatorAsync(l.Key, l.Value);
}
_timer.schedule(this, _timeout);
}
Expand Down Expand Up @@ -457,8 +409,11 @@ public void
}
}

async Task preformFindLocatorAsync(LookupPrx lookupPrx, LookupReplyPrx lookupReplyPrx)
async Task performFindLocatorAsync(LookupPrx lookupPrx, LookupReplyPrx lookupReplyPrx)
{
// Exit the mutex lock before proceeding.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awaiting a remote call with a mutex lock (see below) is incorrect and deadlock prone. It could be the cause for #2813.

await Task.Yield();

// Send multicast request.
try
{
Expand Down Expand Up @@ -507,11 +462,7 @@ private void exception(Exception ex)
_lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
}

if (_pendingRequests.Count == 0)
{
Monitor.Pulse(_mutex);
}
else
if (_pendingRequests.Count > 0)
{
foreach (Request req in _pendingRequests)
{
Expand Down Expand Up @@ -589,11 +540,7 @@ public void runTimerTask()
_lookup.ice_getCommunicator().getLogger().trace("Lookup", s.ToString());
}

if (_pendingRequests.Count == 0)
{
Monitor.Pulse(_mutex);
}
else
if (_pendingRequests.Count > 0)
{
foreach (Request req in _pendingRequests)
{
Expand Down Expand Up @@ -740,12 +687,6 @@ public void
}
}

private List<Ice.LocatorPrx>
getLocators(string instanceName, int waitTime)
{
return _locator.getLocators(instanceName, waitTime);
}

private Ice.Communicator _communicator;
private Ice.ObjectAdapter _locatorAdapter;
private Ice.ObjectAdapter _replyAdapter;
Expand Down