{"action":"created","issue":{"url":"https://api.github.com/repos/bors-ng/bors-ng/issues/254","repository_url":"https://api.github.com/repos/bors-ng/bors-ng","labels_url":"https://api.github.com/repos/bors-ng/bors-ng/issues/254/labels{/name}","comments_url":"https://api.github.com/repos/bors-ng/bors-ng/issues/254/comments","events_url":"https://api.github.com/repos/bors-ng/bors-ng/issues/254/events","html_url":"https://github.com/bors-ng/bors-ng/issues/254","id":247841969,"number":254,"title":"DB timeout / crash","user":{"login":"mithrandi","id":856430,"avatar_url":"https://avatars2.githubusercontent.com/u/856430?v=4","gravatar_id":"","url":"https://api.github.com/users/mithrandi","html_url":"https://github.com/mithrandi","followers_url":"https://api.github.com/users/mithrandi/followers","following_url":"https://api.github.com/users/mithrandi/following{/other_user}","gists_url":"https://api.github.com/users/mithrandi/gists{/gist_id}","starred_url":"https://api.github.com/users/mithrandi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mithrandi/subscriptions","organizations_url":"https://api.github.com/users/mithrandi/orgs","repos_url":"https://api.github.com/users/mithrandi/repos","events_url":"https://api.github.com/users/mithrandi/events{/privacy}","received_events_url":"https://api.github.com/users/mithrandi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-03T21:33:22Z","updated_at":"2017-08-03T21:44:19Z","closed_at":null,"body":"We just started trying out bors-ng internally (running our own instance), and we're getting some errors like this:\r\n```\r\n21:05:39.123 [error] Postgrex.Protocol (#PID<0.306.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.3011.0> timed out because it checked out the connection for longer than 15000ms\r\n21:05:39.124 [error] GenServer #PID<0.3011.0> terminating\r\n** (DBConnection.ConnectionError) tcp recv: closed\r\n    (db_connection) lib/db_connection.ex:794: DBConnection.transaction/3\r\n    (bors_worker) lib/batcher.ex:66: BorsNG.Worker.Batcher.handle_cast/2\r\n    (stdlib) gen_server.erl:601: :gen_server.try_dispatch/4\r\n    (stdlib) gen_server.erl:667: :gen_server.handle_msg/5\r\n    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3\r\nLast message: {:\"$gen_cast\", {:cancel_all}}\r\n```\r\nThey seem to be causing batches to be cancelled or marked \"crash\". From what I can understand, the code is doing something in a transaction and the transaction is running longer than 15 seconds so it's being timed out; I couldn't grok the code well enough to figure out exactly what it's doing in `handle_cast` though. Is there some easy way to work around this? I'm not sure if this is the consequence of being 300ms+ away from GitHub making stuff slow, or some local issue."},"comment":{"url":"https://api.github.com/repos/bors-ng/bors-ng/issues/comments/320098540","html_url":"https://github.com/bors-ng/bors-ng/issues/254#issuecomment-320098540","issue_url":"https://api.github.com/repos/bors-ng/bors-ng/issues/254","id":320098540,"user":{"login":"notriddle","id":1593513,"avatar_url":"https://avatars1.githubusercontent.com/u/1593513?v=4","gravatar_id":"","url":"https://api.github.com/users/notriddle","html_url":"https://github.com/notriddle","followers_url":"https://api.github.com/users/notriddle/followers","following_url":"https://api.github.com/users/notriddle/following{/other_user}","gists_url":"https://api.github.com/users/notriddle/gists{/gist_id}","starred_url":"https://api.github.com/users/notriddle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/notriddle/subscriptions","organizations_url":"https://api.github.com/users/notriddle/orgs","repos_url":"https://api.github.com/users/notriddle/repos","events_url":"https://api.github.com/users/notriddle/events{/privacy}","received_events_url":"https://api.github.com/users/notriddle/received_events","type":"User","site_admin":false},"created_at":"2017-08-03T21:44:19Z","updated_at":"2017-08-03T21:44:19Z","body":"It does sound like a combination of latency with GitHub and my own laziness keeping me from doing more reasonable transaction boundaries.\r\n\r\nI might just remove the transaction wrapping entirely. You'll notice that the `handle_cast` and `handle_info` both use the `Repo.transaction` function. You can try removing the wrapper, making these changes:\r\n\r\n```diff\r\ndiff --git a/apps/bors_worker/lib/batcher.ex b/apps/bors_worker/lib/batcher.ex\r\nindex abfbcfc..04628ae 100644\r\n--- a/apps/bors_worker/lib/batcher.ex\r\n+++ b/apps/bors_worker/lib/batcher.ex\r\n@@ -63,7 +63,7 @@ defmodule BorsNG.Worker.Batcher do\r\n   end\r\n\r\n   def handle_cast(args, project_id) do\r\n-    Repo.transaction(fn -> do_handle_cast(args, project_id) end)\r\n+    do_handle_cast(args, project_id)\r\n     {:noreply, project_id}\r\n   end\r\n\r\n@@ -144,7 +144,7 @@ defmodule BorsNG.Worker.Batcher do\r\n     if repetition != :once do\r\n       Process.send_after(self(), {:poll, repetition}, @poll_period)\r\n     end\r\n-    case Repo.transaction(fn -> poll(project_id) end) do\r\n+    case poll(project_id) do\r\n       {:ok, :stop} ->\r\n         {:stop, :normal, project_id}\r\n       {:ok, :again} ->\r\n```"}}
{"actor":{"display_login":"notriddle"}}