2
votes

I've got a system set up to let a worker process do some job and am coordinating with named pipes between the GUI process and the worker process. I kick off the worker process here:

this.pipeGuidString = Guid.NewGuid().ToString();
var startInfo = new ProcessStartInfo(
  "VidCoderWorker.exe",
  Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture) + " " + this.pipeGuidString);
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
this.worker = Process.Start(startInfo);

// When the process writes out a line, its pipe server is ready and can be contacted for
// work. Reading line blocks until this happens.
this.logger.Log("Worker ready: " + this.worker.StandardOutput.ReadLine());
  bool connectionSucceeded = false;

this.logger.Log("Connecting to process " + this.worker.Id + " on pipe " + this.pipeGuidString);

var binding = new NetNamedPipeBinding
  {
    OpenTimeout = TimeSpan.FromSeconds(10),
    CloseTimeout = TimeSpan.FromSeconds(10),
    SendTimeout = TimeSpan.FromSeconds(10),
    ReceiveTimeout = TimeSpan.FromSeconds(10)
  };

this.pipeFactory = new DuplexChannelFactory<IHandBrakeEncoder>(
  this,
  binding,
  new EndpointAddress("net.pipe://localhost/" + pipeGuid + "/VidCoder"));

this.channel = this.pipeFactory.CreateChannel();
this.channel.Ping();

Then inside the worker process:

host = new ServiceHost(
  typeof (HandBrakeEncoder),
  new Uri[]
    {
      new Uri("net.pipe://localhost/" + PipeGuidString)
    });

host.AddServiceEndpoint(
  typeof (IHandBrakeEncoder),
  new NetNamedPipeBinding(),
  "VidCoder");

host.Open();

encodeComplete = new ManualResetEventSlim(false);
Console.WriteLine("Service state is " + host.State + " on pipe " + PipeGuidString);
encodeComplete.Wait();

host.Close();

It works fine for most people (including me) 100% of the time. But one user reports that the host process always gets an EndpointNotFoundException when trying to connect to the worker process, even with a log that indicates that the GUID was the same on both sides and the state was Opened on the worker process.

I figure that he must have something different with his system that's causing the failure and am wondering what that could be.

  • I've tried connecting via Remote Desktop and that still works for me.
  • I have not changed the Mandatory Integrity level on either process
  • I read this answer so I asked the user to run net localgroup "NETWORK USERS" but the group does not exist for him
  • (edit) Net.Pipe Listener Adapter service was disabled for the user but it still did not work after the user enabled and started it.

Any other ideas about why this would be happening? I read some stuff about local vs global named pipes but since I'm communicating locally and spawning the process locally it didn't seem like it should be an issue.

(edit2) User was surprisingly able to get a WCF trace: http://engy.us/misc/TracesWithNetPipeStarted.svclog

(edit3) It apparently works when running the host process as Administrator. Could it be that in this case some part of the pipe communication was requiring those privileges? How can I set up the pipe channel so that it never needs admin?

2
Possibly an undetected exception in the worker. Do you have it all wrapped in try/catch with exception logging? Or is the worker running from a Task where you don't wait for the Task to finish at some point (which would lose exceptions from the task thread)?Matthew Watson
As stated in this answer, is the Net.Pipe Listener Adapter service running? Also, does the exception have an InnerException?CodeCaster
It's all wrapped in a try/catch with logging. The connection is ready and working as far as the worker is concerned. About the Net.Pipe Listener Adapter service, I don't see it running when things are working correctly on my box. About the InnerException, I'm not logging that right now as it's part of a retry loop... does it normally have helpful information?RandomEngy
The Net.Pipe Listener Adapter was disabled for the user but it still did not work after they enabled and started it.RandomEngy
Did you try to enable wcf trace?evgenyl

2 Answers

3
votes

Take a look at this SOA question and answer, which explains in detail how a WCF NetNamedPipeBinding service which is local to a particular session might be blocked by an unrelated application which is published globally, if the latter's service URL is chosen carelessly.

This seems quite a plausible explanation for the situation you describe.

0
votes

I can confirm that having installed Garmin Express interferes with Named Pipes. For instance, trying to run unit tests in VS in non-admin mode causes the test runner to hang. Uninstalling Garmin Express resolves the issue.