elixir-mongo / mongodb

MongoDB driver for Elixir
Apache License 2.0
571 stars 156 forks source link

Connect to MongoDB Atlas free tier failing with "tcp send: unknown POSIX error - : closed" #332

Closed chris468 closed 4 years ago

chris468 commented 4 years ago

I've been trying to use the elixir mongodb driver connect to MongoDB Atlas free tier but it's failing with "tcp send: unknown POSIX error - : closed". I've tried hosting the Atlas cluster on all 3 cloud platforms, and I've tried with and without the ssl options mentioned here. I can connect with the mongo shell and with the C# driver. Is there something I'm missing?

w/ the latest master:

$ mix --version
Erlang/OTP 21 [erts-10.3] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1]

Mix 1.10.2 (compiled with Erlang/OTP 21)

$ iex -S mix
warning: :simple_one_for_one strategy is deprecated, please use DynamicSupervisor instead
(elixir 1.10.2) lib/supervisor.ex:604: Supervisor.init/2
(elixir 1.10.2) lib/supervisor.ex:556: Supervisor.start_link/2
(stdlib 3.8) supervisor.erl:379: :supervisor.do_start_child_i/3
(stdlib 3.8) supervisor.erl:365: :supervisor.do_start_child/2
(stdlib 3.8) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2

warning: :simple_one_for_one strategy is deprecated, please use DynamicSupervisor instead
(elixir 1.10.2) lib/supervisor.ex:604: Supervisor.init/2
(elixir 1.10.2) lib/supervisor.ex:556: Supervisor.start_link/2
(stdlib 3.8) supervisor.erl:379: :supervisor.do_start_child_i/3
(stdlib 3.8) supervisor.erl:365: :supervisor.do_start_child/2
(stdlib 3.8) supervisor.erl:349: anonymous fn/3 in :supervisor.start_children/2

Interactive Elixir (1.10.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> url = "mongodb+srv://<username>:<password>@<url?>/test?retryWrites=true&w=majority"
"mongodb+srv://<username>:<password>@<url>/test?retryWrites=true&w=majority"
iex(2)> Mongo.start_link(url: url, ssl: true, ssl_opts: [ ciphers: ['AES256-GCM-SHA384'], versions: [:"tlsv1.2"]])
{:ok, #PID<0.198.0>}
iex(3)>
11:34:10.157 [error] Mongo.Protocol (#PID<0.202.0>) failed to connect: ** (Mongo.Error) <url>:27017 tcp send: unknown POSIX error - :closed
iex(3)>
11:34:10.157 [error] Mongo.Protocol (#PID<0.210.0>) failed to connect: ** (Mongo.Error) <url>:27017 tcp send: unknown POSIX error - :closed

11:34:10.157 [error] Mongo.Protocol (#PID<0.206.0>) failed to connect: ** (Mongo.Error) <url>:27017 tcp send: unknown POSIX error - :closed
iex(3)>
11:34:10.159 [info] Mongo.Protocol (#PID<0.210.0>) missed message: {:ssl_closed, {:sslsocket, {:gen_tcp, #Port<0.8>, :
tls_connection, :undefined}, [#PID<0.218.0>, #PID<0.215.0>]}}
iex(3)>
11:34:10.159 [info] Mongo.Protocol (#PID<0.202.0>) missed message: {:ssl_closed, {:sslsocket, {:gen_tcp, #Port<0.9>, :
tls_connection, :undefined}, [#PID<0.219.0>, #PID<0.216.0>]}}
iex(3)>
11:34:10.159 [info] Mongo.Protocol (#PID<0.206.0>) missed message: {:ssl_closed, {:sslsocket, {:gen_tcp, #Port<0.10>,
:tls_connection, :undefined}, [#PID<0.217.0>, #PID<0.214.0>]}}
iex(3)>
ankhers commented 4 years ago

Would you be willing to provide me with a database in order to test against? If you would like to do this privately, you can find my email address on my profile.

chris468 commented 4 years ago

Thinking about how to give you access led me to the problem. I have an IP whitelist in the atlas configuration, and to try and narrow down some connection issues I switched to another machine and forgot to whitelist it. Once I did, I could connect w/ the steps above. I'll go ahead and close this.