Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having trouble starting up ecpool in a simple Erlang program #51

Open
marceln opened this issue Aug 29, 2024 · 3 comments
Open

Having trouble starting up ecpool in a simple Erlang program #51

marceln opened this issue Aug 29, 2024 · 3 comments

Comments

@marceln
Copy link

marceln commented Aug 29, 2024

I'm having issues setting up a basic pool. I'm using this code in my supervisor initialization:

init([]) ->
    PoolSize = 10,
    Urls = ["localhost:27017"],
    Database = "test",
    Username = "test",
    Password = "test",
    Type = single,

    % Define the worker arguments
    WorkerArgs = [
        {hosts, Urls},
        {database, Database},
        {login, Username},
        {password, Password},
        {type, Type}
    ],

    PoolOptions = [
        {pool_size, PoolSize},
        {auto_reconnect, 1},
        {options, []},
        {worker_options, WorkerArgs}
    ],

    PoolSpec = ecpool:pool_spec(?APP, ?APP, mongo_client, PoolOptions),

    {ok, {{one_for_all, 10, 100}, [PoolSpec]}}. 

However, I keep getting this undef error and I can't figure out what's the source of it. Do you have any hints?

Eshell V15.0.1 (press Ctrl+G to abort, type help(). for help)
=CRASH REPORT==== 29-Aug-2024::16:19:21.153000 ===
  crasher:
    initial call: ecpool_worker:init/1
    pid: <0.253.0>
    registered_name: []
    exception exit: undef
      in function  gen_server:init_it/6 (gen_server.erl, line 2038)
    ancestors: [<0.252.0>,<0.250.0>,mongo_app_sup,<0.248.0>]
    message_queue_len: 0
    messages: []
    links: [<0.252.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 233
    stack_size: 29
    reductions: 103
  neighbours:

=SUPERVISOR REPORT==== 29-Aug-2024::16:19:21.158000 ===
    supervisor: {<0.252.0>,ecpool_worker_sup}
    errorContext: start_error
    reason: undef
    offender: [{pid,undefined},
               {id,{worker,1}},
               {mfargs,
                   {ecpool_worker,start_link,
                       [mongo_app,1,mongo_client,
                        [{pool_size,10},
                         {auto_reconnect,1},
                         {options,[]},
                         {worker_options,
                             [{hosts,["localhost:27017"]},
                              {database,"test"},
                              {login,"test"},
                              {password,"test"},
                              {type,single}]}]]}},
               {restart_type,transient},
               {significant,false},
               {shutdown,5000},
               {child_type,worker}]

=SUPERVISOR REPORT==== 29-Aug-2024::16:19:21.158000 ===
    supervisor: {<0.250.0>,ecpool_pool_sup}
    errorContext: start_error
    reason: {shutdown,{failed_to_start_child,{worker,1},undef}}
    offender: [{pid,undefined},
               {id,worker_sup},
               {mfargs,
                   {ecpool_worker_sup,start_link,
                       [mongo_app,mongo_client,
                        [{pool_size,10},
                         {auto_reconnect,1},
                         {options,[]},
                         {worker_options,
                             [{hosts,["localhost:27017"]},
                              {database,"test"},
                              {login,"test"},
                              {password,"test"},
                              {type,single}]}]]}},
               {restart_type,transient},
               {significant,false},
               {shutdown,infinity},
               {child_type,supervisor}]

=SUPERVISOR REPORT==== 29-Aug-2024::16:19:21.158000 ===
    supervisor: {local,mongo_app_sup}
    errorContext: start_error
    reason: {shutdown,
                {failed_to_start_child,worker_sup,
                    {shutdown,{failed_to_start_child,{worker,1},undef}}}}
    offender: [{pid,undefined},
               {id,mongo_app},
               {mfargs,
                   {ecpool,start_pool,
                       [mongo_app,mongo_client,
                        [{pool_size,10},
                         {auto_reconnect,1},
                         {options,[]},
                         {worker_options,
                             [{hosts,["localhost:27017"]},
                              {database,"test"},
                              {login,"test"},
                              {password,"test"},
                              {type,single}]}]]}},
               {restart_type,permanent},
               {significant,false},
               {shutdown,5000},
               {child_type,supervisor}]

=INFO REPORT==== 29-Aug-2024::16:19:21.158000 ===
    application: mongo_app
    exited: {{shutdown,
                 {failed_to_start_child,mongo_app,
                     {shutdown,
                         {failed_to_start_child,worker_sup,
                             {shutdown,
                                 {failed_to_start_child,{worker,1},undef}}}}}},
             {mongo_app_app,start,[normal,[]]}}
    type: temporary

=CRASH REPORT==== 29-Aug-2024::16:19:21.158000 ===
  crasher:
    initial call: application_master:init/3
    pid: <0.247.0>
    registered_name: []
    exception exit: {{shutdown,
                      {failed_to_start_child,mongo_app,
                       {shutdown,
                        {failed_to_start_child,worker_sup,
                         {shutdown,
                          {failed_to_start_child,{worker,1},undef}}}}}},
                     {mongo_app_app,start,[normal,[]]}}
      in function  application_master:init/3 (application_master.erl, line 143)
    ancestors: [application_controller,<0.10.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.248.0>,normal}]
    links: [<0.45.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 376
    stack_size: 29
    reductions: 70
  neighbours:

=INFO REPORT==== 29-Aug-2024::16:19:21.165000 ===
    application: ecpool
    exited: stopped
    type: temporary

=INFO REPORT==== 29-Aug-2024::16:19:21.171000 ===
    application: gproc
    exited: stopped
    type: temporary

=INFO REPORT==== 29-Aug-2024::16:19:21.176000 ===
    application: mongodb
    exited: stopped
    type: temporary

=INFO REPORT==== 29-Aug-2024::16:19:21.176000 ===
    application: pbkdf2
    exited: stopped
    type: temporary

=INFO REPORT==== 29-Aug-2024::16:19:21.176000 ===
    application: poolboy
    exited: stopped
    type: temporary

=INFO REPORT==== 29-Aug-2024::16:19:21.176000 ===
    application: bson
    exited: stopped
    type: temporary

===> Booted sasl
===> Failed to boot mongo_app for reason {{shutdown,
                                           {failed_to_start_child,mongo_app,
                                            {shutdown,
                                             {failed_to_start_child,
                                              worker_sup,
                                              {shutdown,
                                               {failed_to_start_child,
                                                {worker,1},
                                                undef}}}}}},
                                          {mongo_app_app,start,[normal,[]]}}
@id
Copy link

id commented Aug 29, 2024

@marceln do you have mongo_client compiled and available for the app?

@marceln
Copy link
Author

marceln commented Aug 29, 2024

Yes, it's a simple module lying next to the supervisor file:

-module(mongo_client).

-behaviour(ecpool_worker).

-export([connect/1]).

connect(Opts) ->
    erlang:display(Opts),

    Type = proplists:get_value(type, Opts, single),
    Urls = proplists:get_value(hosts, Opts, "localhost:27017"),
    Options = proplists:get_value(options, Opts, [{max_overflow, 0}]),
    WorkerOptions = proplists:get_value(worker_options, Opts, []),
    mongo_api:connect(Type, Urls, Options, WorkerOptions).

@zmstone
Copy link
Member

zmstone commented Aug 29, 2024

I guess the erlang:display did not print anything for you ?
maybe check if the module (beam) is actually loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants