Server crash when using bgw_main for a dynamic bgworker - Mailing list pgsql-hackers

From Michael Paquier
Subject Server crash when using bgw_main for a dynamic bgworker
Date
Msg-id CAB7nPqQE_i6Jf1joxH=usSmnhQy7JXUAvKFt9HXnzboiD7K_bQ@mail.gmail.com
Whole thread Raw
Responses Re: Server crash when using bgw_main for a dynamic bgworker  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Hi all,

While playing a bit with background workers (commit 527ea66), I found that setting bgw_main for a dynamic bgworker, as well as bgw_library_name and bgw_library_name, crashes to server if the library defining the function defined in bgw_main is not loaded. In order to reproduce that, for example simply change bgw_main from NULL to worker_spi_main in worker_spi_launch:worker_spi.c and do not set shared_preload_libraries with worker_spi. Then connect to a server having this modified worker_spi installed and do the following:
postgres=# show shared_preload_libraries ;
 shared_preload_libraries
--------------------------
 
(1 row)
postgres=# create extension worker_spi;
CREATE EXTENSION
postgres=# select worker_spi_launch(1);
 worker_spi_launch
-------------------
 t
(1 row)
postgres=# select worker_spi_launch(2);
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

By looking at the code, priority is given to bgw_main...
    if (worker->bgw_main != NULL)
        entrypt = worker->bgw_main;
    else
        entrypt = (bgworker_main_type)
            load_external_function(worker->bgw_library_name,
                                   worker->bgw_function_name,
                                   true, NULL);
Wouldn't be clearer for the user to add a new flag in BackgroundWorker:bgworker.h to define a class of bgworker? Or at least specify clearly in the docs just to never set bgw_main if the library is not loaded previously using for example shared_preload_libraries?

Opinions?

Regards,
--
Michael

pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: pass-through queries to foreign servers
Next
From: Pavel Raiskup
Date:
Subject: [PATCH] Re: [BUGS] BUG #7815: Upgrading PostgreSQL from 9.1 to 9.2 with pg_upgrade/postgreql-setup fails - invalid status retrieve