pgpool2.git / summary / log / commit / refs

commit    b188728f081de22c052d3c67ab9356cc0df295e1
Author:   Tatsuo Ishii <ishii@sraoss.co.jp>
Date:     Fri Mar 04 11:00:41 2022 +0000

    Fix main process exiting while performing finding primary node.
    
    Pgpool-II main process tries to find primary node whenever the cluster
    status is changed by failover/failback. While doing it, if a backend
    is failing or shutting down, socket write to the backend could
    fail. Unfortunately in the case do_query() throws FATAL error, which
    makes the Pgpool-II main process die like this.
    
    2022-03-04 18:13:12.711: main pid 795826: WARNING:  write on backend 1 failed with error :"Broken pipe"
    2022-03-04 18:13:12.711: main pid 795826: DETAIL:  while trying to write data from offset: 0 wlen: 32
    2022-03-04 18:13:12.711: main pid 795826: LOG:  notice_backend_error: called from pgpool main. ignored.
    2022-03-04 18:13:12.711: main pid 795826: LOG:  unable to flush data to backend
    2022-03-04 18:13:12.711: main pid 795826: DETAIL:  do not failover because I am the main process
    2022-03-04 18:13:12.711: main pid 795826: FATAL:  Backend throw an error message
    2022-03-04 18:13:12.711: main pid 795826: DETAIL:  Exiting current session because of an error from backend
    2022-03-04 18:13:12.711: main pid 795826: HINT:  BACKEND Error: "terminating connection due to administrator command"
    2022-03-04 18:13:12.715: main pid 795826: LOG:  shutting down
    
    To prevent it, change ereport(FATAL) to ereport(ERROR) in do_query().


src/protocol/pool_process_query.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index 9433fbb93..0a0985b6a 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -2098,6 +2098,7 @@ do_query(POOL_CONNECTION * backend, char *query, POOL_SELECT_RESULT * *result, i if (pool_extract_error_message(false, backend, major, true, &message) == 1) { + int etype; /* * This is fatal. Because: If we operate extended query, * backend would not accept subsequent commands until "sync" @@ -2108,6 +2109,8 @@ do_query(POOL_CONNECTION * backend, char *query, POOL_SELECT_RESULT * *result, i * accepted. In summary there's no transparent way for * frontend to handle error case. The only way is closing this * session. + * However if the process type is main process, we should not + * exit the process. */ if (processType == PT_WORKER) { @@ -2118,7 +2121,12 @@ do_query(POOL_CONNECTION * backend, char *query, POOL_SELECT_RESULT * *result, i sleep(pool_config->sr_check_period); } - ereport(FATAL, + if (processType == PT_MAIN) + etype = ERROR; + else + etype = FATAL; + + ereport(etype, (return_code(1), errmsg("Backend throw an error message"), errdetail("Exiting current session because of an error from backend"), [parent: 40138baa88c5]