remote-trait-object
remote-trait-object copied to clipboard
Why the port must be dropped when the context is dropped?
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.
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 I think calling those methods for already shutdown port is a bug, not an error to handle.
@junha1 I don't understand your opinion. What is the desired behavior of Port functions and shutdown?
@majecty I thought shutdown()
taking self
it natural, and I didn't understand why does Seulgi thinks it should take &mut self
.
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.
@sgkim126 If such situation (other holders have not released) happens, it should be a bug.