C# all pipe instances are busy

陌路散爱 提交于 2019-12-21 09:34:36

问题


The following code creates a new thread acting first as a named pipe client for sending parameters and then as a server for retrieving results. After that it executes a function in another AppDomain acting as a named pipe server and after that as a client to send the results back.

public OrderPrice DoAction()
{
  Task<OrderPrice> t = Task<OrderPrice>.Factory.StartNew(NamedPipeClient, parameters);

  if (domain == null)
  {
    domain = AppDomain.CreateDomain(DOMAINNAME);
  }
  domain.DoCallBack(AppDomainCallback);

  return t.Result;
}

static OrderPrice NamedPipeClient(object parameters) {
  OrderPrice price = null;

  using (NamedPipeClientStream stream = new NamedPipeClientStream(PIPE_TO)) {
    stream.Connect();
    SerializeToStream(stream, parameters);
  }

  using (NamedPipeServerStream stream = new NamedPipeServerStream(PIPE_BACK)) {
    stream.WaitForConnection();

    price = (OrderPrice)DeserializeFromStream(stream);
  }

  return price;
}

void AppDomainCallback() {
  OrderPrice price = null;

  using (NamedPipeServerStream stream = new NamedPipeServerStream(PIPE_TO)) {
    stream.WaitForConnection();

    List<object> parameters = (List<object>)DeserializeFromStream(stream);

    if (mi != null)
      price = (OrderPrice)mi.Invoke(action, parameters.ToArray());
}

  using (NamedPipeClientStream stream = new NamedPipeClientStream(PIPE_BACK)) {
    stream.Connect();
    SerializeToStream(stream, price);
  }
}

The code is called once per second on average and it worked fine for 7+ hours. But at some point "system.io.ioexception all pipe instances are busy" is thrown and they wont reconnect anymore after that. Browsing here it seems like it could be because of not properly disposing the pipe objects, but I guess thats all good since they are inside using statements. Does anyone have any clue what could be wrong here? The code is in .NET 4.0 running on windows server 2008.


回答1:


Sounds like it should be a mutex instead of a simple lock

Lock, mutex, semaphore... what's the difference?

as far as the occasional halting, it could be starvation or a deadlock.

This is good reading material for abstracts on what may be happening

http://en.wikipedia.org/wiki/Dining_philosophers_problem



来源:https://stackoverflow.com/questions/18438016/c-sharp-all-pipe-instances-are-busy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!