From 49b0a76ce471418e94874264065fbb08c256a815 Mon Sep 17 00:00:00 2001 From: Tyler Young Date: Sun, 15 Sep 2024 09:09:18 -0500 Subject: [PATCH 1/2] Fix crash due to TCP receive timeout --- lib/whois.ex | 2 +- test/whois_test.exs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/whois.ex b/lib/whois.ex index ed99a03..346d283 100644 --- a/lib/whois.ex +++ b/lib/whois.ex @@ -122,7 +122,7 @@ defmodule Whois do case :gen_tcp.recv(socket, 0, timeout) do {:ok, data} -> recv(socket, acc <> data, opts) - {:error, :etimedout} -> {:error, :timed_out} + {:error, timeout} when timeout in [:etimedout, :timeout] -> {:error, :timed_out} {:error, :closed} -> acc end end diff --git a/test/whois_test.exs b/test/whois_test.exs index 6b80c53..f1a15bb 100644 --- a/test/whois_test.exs +++ b/test/whois_test.exs @@ -88,6 +88,11 @@ defmodule WhoisTest do assert %NaiveDateTime{} = record.expires_at end + @tag :live + test "lookup/1 handles timeouts" do + assert {:error, :timed_out} = Whois.lookup("google.com", recv_timeout: 0) + end + defp wait, do: Process.sleep(2500) end From 1b84b1f660ebe63c8470beebae6f92ffa6f56f2d Mon Sep 17 00:00:00 2001 From: Tyler Young Date: Sun, 15 Sep 2024 09:11:26 -0500 Subject: [PATCH 2/2] Version bump to 0.3.1 --- CHANGELOG.md | 4 ++++ mix.exs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d57a42..8db89d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.3.1 + +- Fix crash when TCP receive times out (`Whois.lookup/2` now correctly returns `{:error, :timed_out}`) + ## v0.3.0 - Add support for custom timeouts via the `:connect_timeout` and `:recv_timeout` diff --git a/mix.exs b/mix.exs index e7b5f7b..0834988 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,7 @@ defmodule Whois.Mixfile do def project do [ app: :whois, - version: "0.3.0", + version: "0.3.1", elixir: "~> 1.12", consolidate_protocols: Mix.env() != :test, elixirc_paths: elixirc_paths(Mix.env()),