elixir-mongo / mongodb

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

(FunctionClauseError) Mongo.Topology.wait_for_connection/3 #271

Closed sunaku closed 5 years ago

sunaku commented 5 years ago

Hello,

I sometimes encounter the following FunctionClauseError after 2 minutes of retrying re-connection:

** (exit) exited in: GenStage.close_stream(%{#Reference<...> => {:subscribed, #PID<0.375.0>, :transient, 500, 1000, 1000}, ...})
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in :gen.call/4
            (stdlib) gen.erl:152: :gen.call(#PID<0.1861.9>, :"$gen_call", :wait_for_connection, -3)
            (elixir) lib/gen_server.ex:986: GenServer.call/3
            (mongodb) lib/mongo/topology.ex:33: Mongo.Topology.wait_for_connection/3
            (mongodb) lib/mongo.ex:822: Mongo.select_servers/4
            (mongodb) lib/mongo.ex:796: Mongo.select_server/3
            (mongodb) lib/mongo.ex:516: Mongo.command/3

But just before reaching the "point of no return" above, I always encounter these recoverable errors:

15:12:44.052 [error] [pid: #PID<0.381.0>, error: %DBConnection.ConnectionError{message: "connection not available because of disconnection"}]
15:12:48.300 [error] GenServer #PID<0.27200.9> terminating
15:12:49.467 [error] Mongo.Protocol (#PID<0.30127.11>) failed to connect: ** (Mongo.Error) tcp connect: address already in use - :eaddrinuse

Thanks for your consideration.

ankhers commented 5 years ago

Thanks for the report. It looks like we need to to verify the timeout is positive before passing it into the GenServer call.

Fixed in fc41b87a948b5dc991e3927cb5c166cf4c508b62.