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

fix: buffer data via cast when not in idle or busy state #359

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.61
1.1.62
12 changes: 11 additions & 1 deletion lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ defmodule Supavisor.DbHandler do
end

# emulate handle_cast
def handle_event(:cast, {:db_cast, caller, bin}, state, %{sock: sock}) do
def handle_event(:cast, {:db_cast, caller, bin}, state, %{sock: sock})
when state in [:idle, :busy] do
Logger.debug(
"DbHandler: state #{state} <-- <-- bin #{inspect(byte_size(bin))} bytes, cast caller: #{inspect(caller)}"
)
Expand All @@ -421,6 +422,15 @@ defmodule Supavisor.DbHandler do
:keep_state_and_data
end

def handle_event(:cast, {:db_cast, caller, bin}, state, %{buffer: buff} = data) do
Logger.debug(
"DbHandler: state #{state} <-- <-- bin #{inspect(byte_size(bin))} bytes, cast caller: #{inspect(caller)}"
)

new_buff = [bin | buff]
{:keep_state, %{data | caller: caller, buffer: new_buff}}
end

def handle_event(_, {closed, _}, :busy, data) when closed in @sock_closed do
{:stop, :db_termination, data}
end
Expand Down
Loading