-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fix for OTP 21.3+. #253
Fix for OTP 21.3+. #253
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,7 +240,7 @@ defmodule Mariaex.Protocol do | |
{:error, error, _} -> | ||
{:error, error} | ||
{:ok, _, _, state} -> | ||
activate(state, state.buffer) |> connected() | ||
{:ok, %{state | buffer: state.buffer, state: :running}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this change has the same semantics as the original code. |
||
end | ||
end | ||
defp handle_handshake(packet(seqnum: seqnum, msg: auth_switch(plugin: plugin, salt: salt) = _packet), nil, state = %{opts: opts}) do | ||
|
@@ -295,63 +295,29 @@ defmodule Mariaex.Protocol do | |
""" | ||
def disconnect(_, state = %{sock: {sock_mod, sock}}) do | ||
msg_send(text_cmd(command: com_quit(), statement: ""), state, 0) | ||
case msg_recv(state) do | ||
{:ok, packet(msg: ok_resp()), _state} -> | ||
sock_mod.close(sock) | ||
{:ok, packet(msg: _), _state} -> | ||
sock_mod.close(sock) | ||
{:error, _} -> | ||
sock_mod.close(sock) | ||
end | ||
_ = sock_mod.recv_active(sock, 0, "") | ||
sock_mod.close(sock) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This started to cause some troubles because there was no good way of knowing if Then again, because the original code always closed the socket regardless of the actual response, it seems unnecessary to do the read, anyways. |
||
:ok | ||
end | ||
|
||
@doc """ | ||
DBConnection callback | ||
""" | ||
def checkout(%{buffer: :active_once, sock: {sock_mod, sock}} = s) do | ||
case setopts(s, [active: :false], :active_once) do | ||
:ok -> sock_mod.recv_active(sock, 0, "") |> handle_recv_buffer(s) | ||
{:disconnect, _, _} = dis -> dis | ||
def checkout(%{sock: {sock_mod, sock}} = s) do | ||
case sock_mod.recv(sock, 0, 0) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was somewhat inspired by the original |
||
{:error, :timeout} -> {:ok, %{s | buffer: <<>>}} | ||
{:error, description} -> do_disconnect(s, {sock_mod, "recv", description, <<>>}) | ||
{:ok, _} -> {:ok, %{s | buffer: <<>>}} | ||
end | ||
end | ||
|
||
defp handle_recv_buffer({:ok, buffer}, s) do | ||
{:ok, %{s | buffer: buffer}} | ||
end | ||
defp handle_recv_buffer({:disconnect, description}, s) do | ||
do_disconnect(s, description) | ||
end | ||
|
||
@doc """ | ||
DBConnection callback | ||
""" | ||
def checkin(%{buffer: buffer} = s) when is_binary(buffer) do | ||
activate(s, buffer) | ||
{:ok, %{s | buffer: <<>>}} | ||
end | ||
|
||
## Fake [active: once] if buffer not empty | ||
defp activate(s, <<>>) do | ||
case setopts(s, [active: :once], <<>>) do | ||
:ok -> {:ok, %{s | buffer: :active_once, state: :running}} | ||
other -> other | ||
end | ||
end | ||
defp activate(%{sock: {mod, sock}} = s, buffer) do | ||
msg = mod.fake_message(sock, buffer) | ||
send(self(), msg) | ||
{:ok, %{s | buffer: :active_once, state: :running}} | ||
end | ||
|
||
defp setopts(%{sock: {mod, sock}} = s, opts, buffer) do | ||
case mod.setopts(sock, opts) do | ||
:ok -> | ||
:ok | ||
{:error, reason} -> | ||
do_disconnect(s, {mod, "setopts", reason, buffer}) | ||
end | ||
end | ||
|
||
@doc """ | ||
DBConnection callback | ||
|
@@ -1236,7 +1202,6 @@ defmodule Mariaex.Protocol do | |
|
||
|
||
def msg_decode(<< len :: size(24)-little-integer, _seqnum :: size(8)-integer, message :: binary>>=header, state) when byte_size(message) >= len do | ||
|
||
{packet, rest} = decode(header, state.state) | ||
{:ok, packet, %{state | buffer: rest}} | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,10 +38,14 @@ defmodule StartTest do | |
backoff_type: :stop] | ||
|
||
Process.flag :trap_exit, true | ||
assert {:error, {%Mariaex.Error{message: "failed to upgraded socket: {:tls_alert, 'unknown ca'}"}, _}} = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original tests didn't work properly for me. I suspect this was a result of the original SSL tests always being skipped, possibly having broken in the past. If I'm mistaken, this may come down to a MySQL error message inconsistency between releases. |
||
Mariaex.Connection.start_link(test_opts) | ||
assert {:error, {%Mariaex.Error{message: "failed to upgraded socket: {:options, {:cacertfile, []}}"}, _}} = | ||
Mariaex.Connection.start_link(Keyword.put(test_opts, :ssl_opts, Keyword.drop(test_opts[:ssl_opts], [:cacertfile]))) | ||
|
||
{:error, %Mariaex.Error{message: message}} = Mariaex.Protocol.connect(test_opts) | ||
assert message = "failed to upgraded socket: {:tls_alert, {:unknown_ca, 'received CLIENT ALERT: Fatal - Unknown CA'}}" | ||
|
||
{:error, %Mariaex.Error{message: message}} = Mariaex.Protocol.connect( | ||
Keyword.put(test_opts, :ssl_opts, Keyword.drop(test_opts[:ssl_opts], [:cacertfile])) | ||
) | ||
assert message = "failed to upgraded socket: {:options, {:cacertfile, []}}" | ||
end | ||
|
||
@tag :socket | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding here was that this was used to "flush" out anything that was currently in the socket buffer. Because that code path is gone, I do not believe there is any further use for this.