elixir-mongo / mongodb

MongoDB driver for Elixir
Apache License 2.0
568 stars 157 forks source link

Connection Error when use SEEDS #198

Closed allanbatista closed 6 years ago

allanbatista commented 6 years ago

This error is raise when use phoenix 1.3.2 in production only with server. When use console ("iex -S mix") works fine.

ELIXIR VERSION

elixir -v
Erlang/OTP 20 [erts-9.1.5] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.5.2

Repo config

config :myapp, MyApp.Repo,
  database: "myapp",
  username: "myapp",
  password: "password",
  seeds: ["127.0.0.1:27017"],
  pool: DBConnection.Poolboy,
  min_pool_size: 10,
  max_pool_size: 20

Mix Lock

%{"amqp": {:hex, :amqp, "0.3.1", "c22887ff851e57c8012a7b340a9a837ae997ee819079e447222100ef2a1a7735", [:mix], [{:amqp_client, "~> 3.6.14", [hex: :amqp_client, repo: "hexpm", optional: false]}, {:rabbit_common, "~> 3.6.14", [hex: :rabbit_common, repo: "hexpm", optional: false]}, {:recon, "~> 2.3.2", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm"},
  "amqp_client": {:hex, :amqp_client, "3.6.14", "523c4a84d7cab9ce19e1ba17274c87f10627e6539735c1f26dfe5ce2d5aad75d", [:make, :rebar3], [{:rabbit_common, "3.6.14", [hex: :rabbit_common, repo: "hexpm", optional: false]}], "hexpm"},
  "bamboo": {:hex, :bamboo, "0.8.0", "573889a3efcb906bb9d25a1c4caa4ca22f479235e1b8cc3260d8b88dabeb4b14", [:mix], [{:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, ">= 1.5.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
  "bamboo_smtp": {:hex, :bamboo_smtp, "1.4.0", "a01d91406f3a46b3452c84d345d50f75d6facca5e06337358287a97da0426240", [:mix], [{:bamboo, "~> 0.8.0", [hex: :bamboo, repo: "hexpm", optional: false]}, {:gen_smtp, "~> 0.12.0", [hex: :gen_smtp, repo: "hexpm", optional: false]}], "hexpm"},
  "certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [:rebar3], [], "hexpm"},
  "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm"},
  "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
  "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
  "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"},
  "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
  "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"},
  "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [], [], "hexpm"},
  "ecto": {:hex, :ecto, "2.1.6", "29b45f393c2ecd99f83e418ea9b0a2af6078ecb30f401481abac8a473c490f84", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
  "ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
  "ex_machina": {:hex, :ex_machina, "2.1.0", "4874dc9c78e7cf2d429f24dc3c4005674d4e4da6a08be961ffccc08fb528e28b", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
  "file_system": {:hex, :file_system, "0.2.4", "f0bdda195c0e46e987333e986452ec523aed21d784189144f647c43eaf307064", [:mix], [], "hexpm"},
  "floki": {:hex, :floki, "0.20.0", "fd018e3e1c7a77cafbe4d51c9811102f701bbbbbd4c818e974ea371348bd0719", [:mix], [{:html_entities, "~> 0.4.0", [hex: :html_entities, repo: "hexpm", optional: false]}, {:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm"},
  "gen_smtp": {:hex, :gen_smtp, "0.12.0", "97d44903f5ca18ca85cb39aee7d9c77e98d79804bbdef56078adcf905cb2ef00", [:rebar3], [], "hexpm"},
  "gettext": {:hex, :gettext, "0.15.0", "40a2b8ce33a80ced7727e36768499fc9286881c43ebafccae6bab731e2b2b8ce", [:mix], [], "hexpm"},
  "goldrush": {:hex, :goldrush, "0.1.9", "f06e5d5f1277da5c413e84d5a2924174182fb108dabb39d5ec548b27424cd106", [], [], "hexpm"},
  "hackney": {:hex, :hackney, "1.11.0", "4951ee019df102492dabba66a09e305f61919a8a183a7860236c0fde586134b6", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
  "html_entities": {:hex, :html_entities, "0.4.0", "f2fee876858cf6aaa9db608820a3209e45a087c5177332799592142b50e89a6b", [:mix], [], "hexpm"},
  "httpoison": {:hex, :httpoison, "1.0.0", "1f02f827148d945d40b24f0b0a89afe40bfe037171a6cf70f2486976d86921cd", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
  "idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
  "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [], [], "hexpm"},
  "lager": {:hex, :lager, "3.5.1", "63897a61af646c59bb928fee9756ce8bdd02d5a1a2f3551d4a5e38386c2cc071", [], [{:goldrush, "0.1.9", [hex: :goldrush, repo: "hexpm", optional: false]}], "hexpm"},
  "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
  "mime": {:hex, :mime, "1.2.0", "78adaa84832b3680de06f88f0997e3ead3b451a440d183d688085be2d709b534", [:mix], [], "hexpm"},
  "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
  "mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm"},
  "mongodb": {:hex, :mongodb, "0.4.4", "8def7abbe77938ac314d94eedecab1778e678d434889383d638ad2a230edd4e3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}], "hexpm"},
  "mongodb_ecto": {:hex, :mongodb_ecto, "0.2.0", "5eccf19f3798c0a5c39428c6d33394b55038f902bd60f7a4fb1f9ffb1f4ece97", [:mix], [{:ecto, "~> 2.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mongodb, "~> 0.4.2", [hex: :mongodb, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix": {:hex, :phoenix, "1.3.2", "2a00d751f51670ea6bc3f2ba4e6eb27ecb8a2c71e7978d9cd3e5de5ccf7378bd", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_ecto": {:hex, :phoenix_ecto, "3.3.0", "702f6e164512853d29f9d20763493f2b3bcfcb44f118af2bc37bb95d0801b480", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_html": {:hex, :phoenix_html, "2.11.0", "ead10dd1e36d5b8b5cc55642ba337832ec62617efd5765cddaa1a36c8b3891ca", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.3", "1d178429fc8950b12457d09c6afec247bfe1fcb6f36209e18fbb0221bdfe4d41", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"},
  "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.0.2", "bfa7fd52788b5eaa09cb51ff9fcad1d9edfeb68251add458523f839392f034c1", [:mix], [], "hexpm"},
  "plug": {:hex, :plug, "1.5.0", "224b25b4039bedc1eac149fb52ed456770b9678bbf0349cdd810460e1e09195b", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
  "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
  "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
  "premailex": {:hex, :premailex, "0.1.4", "b69cf1c13093b0707e862c6a379b814e566f1c007fc246c5c5a349cc8715d75b", [:mix], [{:floki, "~> 0.19", [hex: :floki, repo: "hexpm", optional: false]}, {:httpoison, "~> 0.13 or ~> 1.0", [hex: :httpoison, repo: "hexpm", optional: false]}], "hexpm"},
  "rabbit_common": {:hex, :rabbit_common, "3.6.14", "dc134cd7228f656367e6e6ac88f1f4ef4a63d8a78a2238f52990a4de467708a1", [:make, :rebar3], [{:recon, "2.3.2", [hex: :recon, repo: "hexpm", optional: false]}], "hexpm"},
  "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
  "ranch_proxy_protocol": {:hex, :ranch_proxy_protocol, "1.4.4", "8853b11757a9798e86c7d6d0ff783a8e2e87f77052aad7f1c91108f254ba4a9c", [], [{:ranch, "1.4.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
  "recon": {:hex, :recon, "2.3.2", "4444c879be323b1b133eec5241cb84bd3821ea194c740d75617e106be4744318", [:rebar3], [], "hexpm"},
  "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
  "task_bunny": {:hex, :task_bunny, "0.3.2", "c2f0e11cfe16ce45616c1760b8c934dbea7c12554bf89130677d916d29f2a2ac", [], [{:amqp, "~> 0.3.1", [hex: :amqp, repo: "hexpm", optional: false]}, {:poison, "~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
  "timex": {:hex, :timex, "3.2.1", "639975eac45c4c08c2dbf7fc53033c313ff1f94fad9282af03619a3826493612", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
  "tzdata": {:hex, :tzdata, "0.5.16", "13424d3afc76c68ff607f2df966c0ab4f3258859bbe3c979c9ed1606135e7352", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
  "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"}}

APPLICATION LOG

12:45:47.585 [debug] Processing with MyApp.TemplateController.create/2
  Parameters: %{"body" => "casa", "name" => "ete"}
  Pipelines: [:api]
12:45:47.593 [debug] QUERY ERROR db=2.0ms queue=0.7ms
INSERT coll="templates" document=[body: "casa", name: "ete", _id: #BSON.ObjectId<5aa943aba9516a0005bf2de1>] []
12:45:47.593 [info] Sent 500 in 8ms
12:45:47.596 [error] GenServer #PID<0.604.0> terminating
** (DBConnection.ConnectionError) client #PID<0.639.0> stopped: ** (ArgumentError) argument error
    :erlang.iolist_size([<<0, 0, 0, 0>>, [nil, 46 | "templates"], 0, [[<<51, 0, 0, 0>>, [[["", 2, ["body", 0], [<<5, 0, 0, 0>>, "casa", 0]], 2, ["name", 0], [<<4, 0, 0, 0>>, "ete", 0]], 7, ["_id", 0], <<90, 169, 67, 171, 169, 81, 106, 0, 5, 191, 45, 225>>], 0]]])
    (mongodb) lib/mongo/messages.ex:60: Mongo.Messages.encode/2
    (mongodb) lib/mongo/protocol/utils.ex:61: anonymous fn/2 in Mongo.Protocol.Utils.send/2
    (elixir) lib/enum.ex:1826: Enum."-reduce/3-lists^foldl/2-0-"/3
    (mongodb) lib/mongo/protocol/utils.ex:60: Mongo.Protocol.Utils.send/2
    (mongodb) lib/mongo/protocol/utils.ex:7: Mongo.Protocol.Utils.message/3
    (mongodb) lib/mongo/protocol.ex:280: Mongo.Protocol.message_reply/2
    (mongodb) lib/mongo/protocol.ex:193: Mongo.Protocol.handle_execute/4

    (db_connection) lib/db_connection/connection.ex:258: DBConnection.Connection.handle_cast/2
    (connection) lib/connection.ex:488: Connection.handle_call/3
    (stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:665: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.640.0>): {:stop, #Reference<0.773954947.297533441.62946>, %DBConnection.ConnectionError{message: "client #PID<0.639.0> stopped: ** (ArgumentError) argument error\n    :erlang.iolist_size([<<0, 0, 0, 0>>, [nil, 46 | \"templates\"], 0, [[<<51, 0, 0, 0>>, [[[\"\", 2, [\"body\", 0], [<<5, 0, 0, 0>>, \"casa\", 0]], 2, [\"name\", 0], [<<4, 0, 0, 0>>, \"ete\", 0]], 7, [\"_id\", 0], <<90, 169, 67, 171, 169, 81, 106, 0, 5, 191, 45, 225>>], 0]]])\n    (mongodb) lib/mongo/messages.ex:60: Mongo.Messages.encode/2\n    (mongodb) lib/mongo/protocol/utils.ex:61: anonymous fn/2 in Mongo.Protocol.Utils.send/2\n    (elixir) lib/enum.ex:1826: Enum.\"-reduce/3-lists^foldl/2-0-\"/3\n    (mongodb) lib/mongo/protocol/utils.ex:60: Mongo.Protocol.Utils.send/2\n    (mongodb) lib/mongo/protocol/utils.ex:7: Mongo.Protocol.Utils.message/3\n    (mongodb) lib/mongo/protocol.ex:280: Mongo.Protocol.message_reply/2\n    (mongodb) lib/mongo/protocol.ex:193: Mongo.Protocol.handle_execute/4\n"}, %{connection_type: :client, database: "jaiminho_production", host: "172.31.22.101:27017", request_id: 0, socket: {:gen_tcp, #Port<0.15395>}, ssl: false, timeout: 5000, topology_pid: #PID<0.475.0>, wire_version: 5, write_concern: %{w: 1}}}
State: {Mongo.Protocol, %{connection_type: :client, database: "jaiminho_production", host: "172.31.22.101:27017", request_id: 0, socket: {:gen_tcp, #Port<0.15395>}, ssl: false, timeout: 5000, topology_pid: #PID<0.475.0>, wire_version: 5, write_concern: %{w: 1}}}
Client #PID<0.640.0> is alive
    (stdlib) gen.erl:169: :gen.do_call/4
    (stdlib) gen_server.erl:210: :gen_server.call/3
    (db_connection) lib/db_connection/connection.ex:454: DBConnection.Connection.sync_stop/5

12:45:47.604 [error] #PID<0.639.0> running MyApp.Endpoint terminated
Server: meudomain-example.com:80 (http)
Request: POST /templates
** (exit) an exception was raised:
    ** (ArgumentError) argument error
        :erlang.iolist_size([<<0, 0, 0, 0>>, [nil, 46 | "templates"], 0, [[<<51, 0, 0, 0>>, [[["", 2, ["body", 0], [<<5, 0, 0, 0>>, "casa", 0]], 2, ["name", 0], [<<4, 0, 0, 0>>, "ete", 0]], 7, ["_id", 0], <<90, 169, 67, 171, 169, 81, 106, 0, 5, 191, 45, 225>>], 0]]])
        (mongodb) lib/mongo/messages.ex:60: Mongo.Messages.encode/2
        (mongodb) lib/mongo/protocol/utils.ex:61: anonymous fn/2 in Mongo.Protocol.Utils.send/2
        (elixir) lib/enum.ex:1826: Enum."-reduce/3-lists^foldl/2-0-"/3
        (mongodb) lib/mongo/protocol/utils.ex:60: Mongo.Protocol.Utils.send/2
        (mongodb) lib/mongo/protocol/utils.ex:7: Mongo.Protocol.Utils.message/3
        (mongodb) lib/mongo/protocol.ex:280: Mongo.Protocol.message_reply/2
        (mongodb) lib/mongo/protocol.ex:193: Mongo.Protocol.handle_execute/
ankhers commented 6 years ago

Do you mind sharing the solution here in case anyone else has a similar problem?

scottmessinger commented 6 years ago

I ran into the same issue :-( I'm using:

It seems it's breaking when doing IO.iodata_length(iodata) when iodata is the query encoded by encode_op(op_query(...)

Previously, I was using ecto 2 and the 0.2.0 of the mongo driver. This happened after I upgraded the dependencies. I'm not sure, but I wonder if it's a problem with my Mongo version -- any idea if that could be related?

scottmessinger commented 6 years ago

Also, forgot to mention:

This fails MyApp.Repo.get(MyApp.Planbook, "5b23e072240bee0007a1a82e")

But this works: Mongo.find(MyApp.Repo.Pool, "planbooks_", %{_id: BSON.ObjectId.decode!("5b23e072240bee0007a1a82e")}) |> Enum.to_list()

I would have thought they both would have failed given the error message, so I'm a bit confused.

ankhers commented 6 years ago

When you say it fails, do you mean an actual error, or does it just not find the record? What if you do

MyApp.Repo.one(from p in MyApp.Planbook, where: p.id == ^"5b23e072240bee0007a1a82e"
scottmessinger commented 5 years ago

We took a break in upgrading to Ecto 2.1, but we're back and figured it out. It turned out to be some odd compile related issue. I changed my dockerfile from this:

# Before
RUN mix deps.clean --all --build && mix deps.get && mix deps.compile
...
RUN mix compile 

To this

RUN mix deps.clean --all --build && mix deps.get && mix deps.compile
...
RUN mix compile && mix deps.clean mongodb && mix deps.get mongodb && mix deps.compile mongodb

And it worked. So odd.