You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/08/16 23:40:20 UTC

[jira] [Commented] (COUCHDB-3102) The xxx_config_listener doesn't restart after a failure

    [ https://issues.apache.org/jira/browse/COUCHDB-3102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15423600#comment-15423600 ] 

ASF GitHub Bot commented on COUCHDB-3102:
-----------------------------------------

GitHub user iilyak opened a pull request:

    https://github.com/apache/couchdb-config/pull/11

     Move responsibility to re-add handler to config

    We move responsibility to re-add handler from config_listener behaviour
    to config_listener_mon module.
    
    gen_event behaviour is a tricky one. Due to its prehistoric times it
    uses links instead of monitors (which didn't exist at that time). This
    makes dealing with gen_event manager restart tricky.
    
    We use {swap_handler, Reason, OldState, NewHandler, NewState} reply from
    handle_event callback to be able to catch any exception from
    Mod:handle_config_change. Effectively preventing gen_event manager from
    killing config_listener_mon process. This trick allows us:
    
      - detect all kinds of failures and re-add handler
      - detect crash of gen_event manager to restart config_listener_mon
    
    As a result of this change the config_listener behaviour modules need to
    be updated to remove following code:
    
        handle_config_terminate(_Server, _Reason, State) ->
            spawn(fun() ->
                timer:sleep(5000),
                config:listen_for_changes(?MODULE, State)
            end).
    
    The handler would be re-added automatically. You can disable this
    behaviour by returning `remove_handler` atom from handle_config_terminate/3
    
    COUCHDB-3102

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/cloudant/couchdb-config 3102-restart-monitor

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/couchdb-config/pull/11.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #11
    
----
commit 7402d78539bca11d99e4cd9f29f25263f4107fe6
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Date:   2016-08-15T23:55:09Z

    Consider only needed handlers in n_handlers
    
    When testing. Make sure we don't count other config_event handlers
    present in the system.

commit e936d6a470d5bcec880c474c00f9bf935c42d404
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Date:   2016-08-16T22:56:34Z

    Fix compilation warning

commit 99f38142d5446206f4878e895648304ff8303642
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Date:   2016-08-16T20:52:12Z

    Move responsibility to re-add handler to config
    
    We move responsibility to re-add handler from config_listener behaviour
    to config_listener_mon module.
    
    gen_event behaviour is a tricky one. Due to its prehistoric times it
    uses links instead of monitors (which didn't exist at that time). This
    makes dealing with gen_event manager restart tricky.
    
    We use {swap_handler, Reason, OldState, NewHandler, NewState} reply from
    handle_event callback to be able to catch any exception from
    Mod:handle_config_change. Effectively preventing gen_event manager from
    killing config_listener_mon process. This trick allows us:
    
      - detect all kinds of failures and re-add handler
      - detect crash of gen_event manager to restart config_listener_mon
    
    As a result of this change the config_listener behaviour modules need to
    be updated to remove following code:
    
        handle_config_terminate(_Server, _Reason, State) ->
            spawn(fun() ->
                timer:sleep(5000),
                config:listen_for_changes(?MODULE, State)
            end).
    
    The handler would be re-added automatically. You can disable this
    behaviour by returning `remove_handler` atom from handle_config_terminate/3
    
    COUCHDB-3102

----


> The xxx_config_listener doesn't restart after a failure
> -------------------------------------------------------
>
>                 Key: COUCHDB-3102
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-3102
>             Project: CouchDB
>          Issue Type: Bug
>            Reporter: ILYA
>
> The [config_listener_mon|https://github.com/apache/couchdb-config/blob/master/src/config_listener_mon.erl#L44] monitors the caller. 
> However in lots of places we use [following pattern|https://github.com/apache/couchdb-chttpd/blob/master/src/chttpd_config_listener.erl#L45:L49]
> {code}
> handle_config_terminate(_Server, _Reason, State) ->
>     spawn(fun() ->
>         timer:sleep(5000),
>         config:listen_for_changes(?MODULE, State)
>     end).
> {code}
> In this case the spawned fun exits right after the monitor has been established.
> Which means config_listener_mon would terminate. Effectively removing event handler from config_event process (gen_event event manager).
> When this happen any further configuration changes get unnoticed by processes.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)