justinstenning / SharedMemory

C# shared memory classes for sharing data between processes (Array, Buffer and Circular Buffer)
https://www.nuget.org/packages/SharedMemory
Other
566 stars 118 forks source link

Reuse existing rpcName #50

Closed ordinaryorange closed 4 years ago

ordinaryorange commented 4 years ago

Is there a way for a new master to reuse the rpcName of a master that has previously disposed ?

Currently I have to restart the slave if the master restarts. I have a use case where the slave continuously runs, but the master process will restart.

I have a workaround, by way of using a normal file to communicate the new master rpcName to the slave, but it is a hack.

justinstenning commented 4 years ago

@ordinaryorange are you explicitly disposing the RpcBuffer? If not, could you try doing that to see if that helps?

There is a mutex created to determine if the master has been created already or not. This should be released when the RpcBuffer is disposed of, and in the case of your master closing, should mean that the master can be created again with the same name.

ordinaryorange commented 4 years ago

I was not explicitly disposing the buffer, so I amended my code, but still no luck.

It appears the slave might be holding onto the mutex?. If I restart the master but not the slave I get an IOException Cannot create a file when that file already exists. But if I also restart the slave, then the master can reuse the rpcName.

justinstenning commented 4 years ago

The slave instance does not hold onto a mutex, however the error makes sense because the underlying MMF is still open and therefore cannot be created by your host.

Unfortunately there is no support currently for "CreateOrOpen" for the underlying buffer when the instance type is master, so you would need to detect the close and then also close the client.

ordinaryorange commented 4 years ago

Ok. Thanks for the help. I did a hack to communicate a new rpcName to the slave via a file, so it could cycle, but was very ordinary. I've just had an idea maybe to use two channels as a workaround.