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

Prod deploy #282

Merged
merged 5 commits into from
Jan 24, 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.18
1.1.21
16 changes: 13 additions & 3 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defmodule Supavisor.ClientHandler do

def init(ref, trans, opts) do
Process.flag(:trap_exit, true)
H.set_max_heap_size(150)

{:ok, sock} = :ranch.handshake(ref)
:ok = trans.setopts(sock, active: true)
Expand Down Expand Up @@ -526,12 +527,21 @@ defmodule Supavisor.ClientHandler do
:ok
end

def terminate(_reason, _state, %{db_pid: {_, pid}}) do
if Db.get_state(pid) == :busy, do: Db.stop(pid)
def terminate(reason, _state, %{db_pid: {_, pid}}) do
if Db.get_state(pid) == :busy do
Logger.warning("Kill DbHandler #{inspect(pid)}, reason #{inspect(reason)}")
Db.stop(pid)
else
Logger.warning("ClientHanlder termination with reason #{inspect(reason)}")
end

:ok
end

def terminate(_reason, _state, _data), do: :ok
def terminate(reason, _state, _data) do
Logger.warning("ClientHanlder termination with reason #{inspect(reason)}")
:ok
end

## Internal functions

Expand Down
4 changes: 3 additions & 1 deletion lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ defmodule Supavisor.DbHandler do
@impl true
def init(args) do
Process.flag(:trap_exit, true)
H.set_max_heap_size(150)

{_, tenant} = args.tenant
Logger.metadata(project: tenant, user: args.user, mode: args.mode)

Expand Down Expand Up @@ -384,7 +386,7 @@ defmodule Supavisor.DbHandler do
Logger.error("Client handler #{inspect(pid)} went down with reason #{inspect(reason)}")
end

if state == :busy do
if state == :busy || data.mode == :session do
:ok = sock_send(data.sock, <<?X, 4::32>>)
:ok = :gen_tcp.close(elem(data.sock, 1))
{:stop, :normal, data}
Expand Down
13 changes: 13 additions & 0 deletions lib/supavisor/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,17 @@ defmodule Supavisor.Helpers do
kind, reason -> {:error, {:badrpc, {kind, reason}}}
end
end

@doc """
Sets the maximum heap size for the current process. The `max_heap_size` parameter is in megabytes.

## Parameters

- `max_heap_size`: The maximum heap size in megabytes.
"""
@spec set_max_heap_size(pos_integer()) :: map()
def set_max_heap_size(max_heap_size) do
max_heap_words = div(max_heap_size * 1024 * 1024, :erlang.system_info(:wordsize))
Process.flag(:max_heap_size, %{size: max_heap_words})
end
end
Loading