You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "antkiller996 (via GitHub)" <gi...@apache.org> on 2023/10/24 06:09:25 UTC

[I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

antkiller996 opened a new issue, #2424:
URL: https://github.com/apache/brpc/issues/2424

   **Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**
   
   
   
   **Describe the solution you'd like (描述你期望的解决方法)**
   希望ServerOption提供OnNewConnection, OnClosedConnection的回调, 以便在用户代码中管理连接信息。
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1782171574

   client端不需要。如果client与server端发起主动关闭链接,server端这边要回调;server端与client端主动发起的,也要回调;另外SocketFailed和close(fd)这两个时机其实无所谓,最好是能保证exactly once的语义。当OnCloseConnection回调执行完后,保证server端fd不能读写即可


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1780652759

   如果说没有短期支持计划,那我来提PR支持下~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1782359046

   > ServerOptions.auth 这个倒是可以在每次新建连接的时候被调用,这就可以实现OnNewConnection的回调。而且可以返回一个AuthContext,这个AuthContext可以通过后续的请求的Controller中拿到。这个AuthContext会存在Socket对象中,当Socket回收(即连接断开)时,AuthContext会被释放。如果把AuthContext的析构函数改为虚函数,允许子类自定义析构的逻辑,是不是就可以实现OnClosedConnection的回调了?
   > 
   > https://github.com/apache/brpc/blob/master/src/brpc/authenticator.h#L30
   
   这个方案貌似可行,但是还是需要对brpc进行改造:
   1. AuthContext 对继承开放,析构函数需要virtual
   2. 现在AuthContext是在Socket::mutable_auth_context中创建的,用户没有控制权让其创建用户的类型。
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1844118514

   > ServerOptions.auth 这个倒是可以在每次新建连接的时候被调用,这就可以实现OnNewConnection的回调。而且可以返回一个AuthContext,这个AuthContext可以通过后续的请求的Controller中拿到。这个AuthContext会存在Socket对象中,当Socket回收(即连接断开)时,AuthContext会被释放。如果把AuthContext的析构函数改为虚函数,允许子类自定义析构的逻辑,是不是就可以实现OnClosedConnection的回调了?
   > 
   > https://github.com/apache/brpc/blob/master/src/brpc/authenticator.h#L30
   
   这里Socket回收好像不等价于连接断开,我看done closure执行完,也调用controller的析构函数,最终也能调用的OnRecycle()
   ![image](https://github.com/apache/brpc/assets/126752534/1301617c-fbde-4911-8ae6-4f40c32993d1)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1780772715

   OnClosedConnection关注的是Socket Failed的时机还是close(fd)的时机?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1778625091

   可以考虑用 [streaming rpc](https://github.com/apache/brpc/blob/master/docs/cn/streaming_rpc.md) 吗?一个stream对应一个session


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1782218262

   ServerOptions.auth 这个倒是可以在每次新建连接的时候被调用,这就可以实现OnNewConnection的回调。而且可以返回一个AuthContext,这个AuthContext可以通过后续的请求的Controller中拿到。这个AuthContext会存在Socket对象中,当Socket回收(即连接断开)时,AuthContext会被释放。如果把AuthContext的析构函数改为虚函数,允许子类自定义析构的逻辑,是不是就可以实现OnClosedConnection的回调了?
   
   https://github.com/apache/brpc/blob/master/src/brpc/authenticator.h#L30


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1782243214

   如果只需要在Socket Failed的时候回调的话,使用Socket::NotifyOnFailed可以实现OnClosedConnection的回调。
   https://github.com/apache/brpc/blob/761b399e50ba95dddec363662a1bf0b42254f18f/src/brpc/socket.cpp#L1044-L1058
   
   可以参考Controller::NotifyOnCancel的用法:
   https://github.com/apache/brpc/blob/761b399e50ba95dddec363662a1bf0b42254f18f/src/brpc/controller.cpp#L539-L561
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1782169598

   client端的连接也需要回调?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1782747516

   > 我们可以在AuthContext新增属性:on_destroy_context(AuthContext* ctx), 用户通过out_ctx->set_destroy_context注册回调。
   > 
   > 在Socket::OnRecycle中delete _auth_context 之前,调用其on_destroy_context回调函数。
   
   看起来可行。可以直接在AuthContext的析构函数里调用 on_destroy_context


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1778780542

   目前来说不太行,不一定要streaming的。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1780991137

   client和server close都需要关注到。EPOLLHUP 可以解决这个事么


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] server支持OnNewConnection(...), OnClosedConnection(...)回调 (brpc)

Posted by "antkiller996 (via GitHub)" <gi...@apache.org>.
antkiller996 commented on issue #2424:
URL: https://github.com/apache/brpc/issues/2424#issuecomment-1783660291

   > > 我们可以在AuthContext新增属性:on_destroy_context(AuthContext* ctx), 用户通过out_ctx->set_destroy_context注册回调。
   > > 在Socket::OnRecycle中delete _auth_context 之前,调用其on_destroy_context回调函数。
   > 
   > 看起来可行。可以直接在AuthContext的析构函数里调用 on_destroy_context
   析构函数函数内不能安全地访问成员变量。针对最初的需求,我们是要在on_destroy_context中获取到存在AuthContext里的一些成员的。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org