remote-trait-object icon indicating copy to clipboard operation
remote-trait-object copied to clipboard

Why the port must be dropped when the context is dropped?

Open sgkim126 opened this issue 4 years ago • 6 comments

https://github.com/CodeChain-io/remote-trait-object/blob/7ac07c741059ae583a05143a62cd6b07898e1c0b/remote-trait-object/src/context.rs#L63

Currently, it fails to drop the context when the port is still held by others. But, there is no way to guarantee whether all other holders released before the context dropped. How about dropping context calls shutdown and making the methods of the Port returns a Result? It also should make the shutdown of the Port takes the mutable reference of the self. It means the user can access the port after shutdown, but I think this would be safer.

sgkim126 avatar Jun 28 '20 09:06 sgkim126

there is no way to guarantee whether all other holders released before the context dropped. Yes, it is a problem.

What I understand is that changing the signature of call, delete_request, and register to return Result. They will return Err if the port shutdown.

// Before
pub trait Port: std::fmt::Debug + Send + Sync + 'static {
    fn call(&self, packet: PacketView) -> Packet;
    fn delete_request(&self, id: ServiceObjectId);
    fn register(&self, service_object: Arc<dyn Dispatch>) -> HandleToExchange;
}
// After
pub trait Port: std::fmt::Debug + Send + Sync + 'static {
    // Return Error if port is shutdown
    fn call(&self, packet: PacketView) -> Result<Packet>;
    // Return Error if port is shutdown
    fn delete_request(&self, id: ServiceObjectId) -> Result<()>;
    // Return Error if port is shutdown
    fn register(&self, service_object: Arc<dyn Dispatch>) -> Result<HandleToExchange>;
}

It looks good to me.

majecty avatar Jun 29 '20 03:06 majecty

@majecty I think calling those methods for already shutdown port is a bug, not an error to handle.

junha1 avatar Jun 29 '20 03:06 junha1

@junha1 I don't understand your opinion. What is the desired behavior of Port functions and shutdown?

majecty avatar Jun 29 '20 03:06 majecty

@majecty I thought shutdown() taking self it natural, and I didn't understand why does Seulgi thinks it should take &mut self.

junha1 avatar Jun 29 '20 03:06 junha1

So the original shutdown code has the problem: But, there is no way to guarantee whether all other holders released before the context dropped.. If you don't understand Seulgi's suggestion, please ask it to Seulgi.

majecty avatar Jun 29 '20 05:06 majecty

@sgkim126 If such situation (other holders have not released) happens, it should be a bug.

junha1 avatar Jun 29 '20 06:06 junha1