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

Reply via email to