comtihon / mongodb-erlang

MongoDB driver for Erlang
Apache License 2.0
341 stars 267 forks source link

Issue connecting to ReplicaSet #225

Closed ivan-perl closed 3 years ago

ivan-perl commented 4 years ago

Hi,

I'm trying to connect to a ReplicaSet but getting different errors and after all connection failing.

Case number 1: Connecting to the ReplicaSet in K8 cluster. Code to connect:

 {ok, Connection} = 
                    mongoc:connect({ rs, <<"rs0">>, ["server1:27017", "server2:27017", "server3:27017"] },
                                                [],
                                                [{database, <<"dbName">>},
                                                 {login, <<"userName">>},
                                                 {password, <<"password">>}]).

As a result I see exceptions in the logs pointing to some bad_match error in code:

** Reason for termination ==
** {{badmatch,[]},
    [{mc_topology,parse_ismaster,4,
                  [{file,"/usr/src/app/server_core/_build/default/lib/mongodb/src/mongoc/mc_topology.erl"},
                   {line,204}]},
     {mc_topology,handle_cast,2,
                  [{file,"/usr/src/app/server_core/_build/default/lib/mongodb/src/mongoc/mc_topology.erl"},
                   {line,145}]},
     {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,637}]},
     {gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,711}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}

There is a huge error message, so I can provide other parts if needed.

Case number 2: Connecting MongoDB service from outside K8 cluster.

In this case I'm doing a port forwarding to local host and trying to connect to forwarded port like this:

{ok, Connection} = mongoc:connect({ unknown, [ "localhost:27018" ] },
                                        Conf,
                                        [{database, MongoDBName},
                                        {login, MongoDBUserName},
                                        {password, MongoDBPassword}]).

I also tried

{ok, Connection} = mongoc:connect({ single, "localhost:27018" }

Result is following:

=ERROR REPORT==== 22-May-2020::16:37:22 ===
** Generic server <0.112.0> terminating
** Last message in was {'EXIT',<0.111.0>,killed}
** When Server state == {state,rsPrimary,"localhost",27018,<0.110.0>,
                               <0.111.0>,
                               [{name,m_pool_name},
                                {register,storage_mongodb_connection_pool},
                                {pool_size,1},
                                {max_overflow,1},
                                {connectTimeoutMS,10000},
                                {socketTimeoutMS,10000},
                                {serverSelectionTimeoutMS,30000},
                                {waitQueueTimeoutMS,10000},
                                {heartbeatFrequencyMS,10000},
                                {minHeartbeatFrequencyMS,1000},
                                {rp_mode,primary}],
                               [{database,<<"DBName">>},
                                {login,<<"DBLogin">>},
                                {password,<<"DBPassword">>}],
                               undefined,10000,10000,1000,<0.139.0>,1}
** Reason for termination ==
** killed

After first error like shown above there is an endless flow of alike messages with only one difference in first line:

** When Server state == {state,undefined,"localhost",27018,<0.110.0>,

In both cases I can connect to the Mongo using CLI client and Compass clients and they are working fine. That is why login/password/dbName/hosts/ports are correct.

MongoDB Server version is 4.0.15

I tried with locally installed single-node 4.0.18 Server and everything worked well. Issues with cluster deployment only.

Please, advice.

Thank you in advance,

Regards, Ivan

dmsnell commented 3 years ago

@comtihon I think this is a duplicate of the newer #226 but #226 has more discussion. Is it worth closing?

comtihon commented 3 years ago

correct.