Skip to content

Commit

Permalink
proxy: fix crash not recovering
Browse files Browse the repository at this point in the history
  • Loading branch information
RTUnreal committed Jul 22, 2024
1 parent 870b519 commit 4573adc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions service/proxy/lib/proxy.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
defmodule Proxy do
use Task, restart: :permanent
require Logger

def start_link(port) do
Task.start_link(__MODULE__, :accept, [port])
end

def accept(port) do
{:ok, socket} = :gen_tcp.listen(port, [:binary, packet: :raw, active: false, reuseaddr: true])
Logger.info("Accepting connections on port #{port}")
Expand Down Expand Up @@ -50,6 +55,7 @@ defmodule Proxy do

# don't allow connections to restricted services
service_permissions = Map.get(hosts_acls, host)

if service_permissions != nil and not service_permissions do
throw_socks_error(
socket,
Expand Down
2 changes: 1 addition & 1 deletion service/proxy/lib/proxy/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Proxy.Application do

children = [
{Task.Supervisor, name: Proxy.TaskSupervisor},
{Task, fn -> Proxy.accept(port) end},
{Proxy, port},
Proxy.Scheduler,
{Proxy.UserCache, name: Proxy.UserCache},
{MyXQL, username: "proxy", hostname: "db", database: "pod", name: :myxql, pool_size: 8}
Expand Down

0 comments on commit 4573adc

Please sign in to comment.