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: bind admin server to the same host #3512

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions postgrest.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ library
, http-types >= 0.12.2 && < 0.13
, insert-ordered-containers >= 0.2.2 && < 0.3
, interpolatedstring-perl6 >= 1 && < 1.1
, iproute >= 1.7.0 && < 1.8
, jose >= 0.8.5.1 && < 0.12
, lens >= 4.14 && < 5.3
, lens-aeson >= 1.0.1 && < 1.3
Expand Down
16 changes: 14 additions & 2 deletions src/PostgREST/AppState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ import PostgREST.SchemaCache (SchemaCache (..),
import PostgREST.SchemaCache.Identifiers (dumpQi)
import PostgREST.Unix (createAndBindDomainSocket)

import Data.Streaming.Network (bindPortTCP, bindRandomPortTCP)
import Data.IP (fromHostAddress, fromHostAddress6)
import Data.Streaming.Network (HostPreference, bindPortTCP,
bindRandomPortTCP)
import Data.String (IsString (..))
import Protolude

Expand Down Expand Up @@ -207,11 +209,21 @@ initSockets AppConfig{..} = do

adminSock <- case cfg'adminport of
Just adminPort -> do
adminSock <- bindPortTCP adminPort (fromString $ T.unpack cfg'host)
hp <- resolvedAddress sock -- reuse the same host as the main socket
adminSock <- bindPortTCP adminPort $ fromMaybe (fromString $ T.unpack cfg'host) hp
pure $ Just adminSock
Nothing -> pure Nothing

pure (sock, adminSock)
where
resolvedAddress :: NS.Socket -> IO (Maybe HostPreference)
resolvedAddress sock = do
sn <- NS.getSocketName sock
case sn of
NS.SockAddrInet _ hostAddr -> pure $ Just $ fromString $ show $ fromHostAddress hostAddr
NS.SockAddrInet6 _ _ hostAddr6 _ -> pure $ Just $ fromString $ show $ fromHostAddress6 hostAddr6
_ -> pure Nothing


initPool :: AppConfig -> ObservationHandler -> IO SQL.Pool
initPool AppConfig{..} observer =
Expand Down
Loading