Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bypass randomly fails with eaddrinuse error #121

Open
ananthakumaran opened this issue Feb 10, 2022 · 0 comments
Open

bypass randomly fails with eaddrinuse error #121

ananthakumaran opened this issue Feb 10, 2022 · 0 comments

Comments

@ananthakumaran
Copy link

{{:badmatch, {:error, :eaddrinuse}},
 [
   {Bypass.Instance, :do_up, 2, [file: 'lib/bypass/instance.ex', line: 322]},
   {Bypass.Instance, :init, 1, [file: 'lib/bypass/instance.ex', line: 34]},
   {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 374]},
   {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 342]},
   {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
 ]}

The race condition could be reproduced with the following script

defmodule BypassReproTest.Case do
  use ExUnit.Case, async: true

  test "reproduce bypass" do
    :ok = :hackney_pool.start_pool(:first_pool, timeout: 15000, max_connections: 100)
    Application.put_env(:bypass, :test_framework, :espec)

    1..10_000
    |> Task.async_stream(
      fn i ->
        bypass = Bypass.open()

        Bypass.stub(bypass, "GET", "/ping", fn conn ->
          Plug.Conn.resp(conn, 200, "pong")
        end)

        response =
          HTTPoison.get!("http://localhost:#{bypass.port}/ping", [], hackney: [pool: :bypass])

        assert response.status_code == 200
        Bypass.verify_expectations!(bypass)
      end,
      ordered: false,
      max_concurrency: 50,
      timeout: 50000
    )
    |> Stream.run()
  end
end

The Code.ensure_loaded should be commented out as well.

  if Code.ensure_loaded?(ESpec) do
    defp verify_expectations!(:espec, bypass) do
      do_verify_expectations(bypass.pid, ESpec.AssertionError)
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant