-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Display an actual TCP port app is bound to #3034
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3eb028f
app: quick'n'dirty displaying of bound port
develop7 eff8e1a
postgrest style
develop7 f7c5697
create app sockets ourselves
develop7 41df536
fix leftover errors
develop7 ab5bc73
cabal: add streaming-commons
develop7 b47a358
spec: fix tests
develop7 4e38128
admin: fixed crash in reachMainApp
develop7 6081cd6
postgrest-style
develop7 394b894
postgrest-style
develop7 17306e3
get unix socket runtime check back
develop7 44075d4
postgrest-style
develop7 364f2d2
bind then listen
develop7 759094a
use setPerms from unix-compat
develop7 95f665f
style
develop7 50925df
pin unix-compat for warp
develop7 7d21a49
put Unix specifics to Postgrest.Unix
develop7 846bf5d
forgot .cabal
develop7 30495e6
fix windows build
develop7 93c3953
fix installSignalHandlers stub
develop7 b09804e
move domain socket avail check to Unix
develop7 b9642a3
exe: drop network from deps
develop7 7fe26dc
style
develop7 e56e857
unpin unix-compat
develop7 56d524c
Update postgrest.cabal
steve-chavez 9df15e1
Update postgrest.cabal
steve-chavez 77a9345
test/io: test random port assignment
develop7 904f01d
style
develop7 bee8c8b
delete outdated comment add CHANGELOG
steve-chavez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module PostgREST.Admin | ||
( runAdmin | ||
) where | ||
|
||
import qualified Data.Text as T | ||
import qualified Hasql.Session as SQL | ||
import qualified Network.HTTP.Types.Status as HTTP | ||
import qualified Network.Wai as Wai | ||
|
@@ -22,19 +20,20 @@ import PostgREST.Config (AppConfig (..)) | |
import qualified PostgREST.AppState as AppState | ||
|
||
import Protolude | ||
import Protolude.Partial (fromJust) | ||
|
||
runAdmin :: AppConfig -> AppState -> Warp.Settings -> IO () | ||
runAdmin conf@AppConfig{configAdminServerPort} appState settings = | ||
whenJust configAdminServerPort $ \adminPort -> do | ||
AppState.logWithZTime appState $ "Admin server listening on port " <> show adminPort | ||
void . forkIO $ Warp.runSettings (settings & Warp.setPort adminPort) adminApp | ||
whenJust (AppState.getSocketAdmin appState) $ \adminSocket -> do | ||
AppState.logWithZTime appState $ "Admin server listening on port " <> show (fromIntegral (fromJust configAdminServerPort) :: Integer) | ||
void . forkIO $ Warp.runSettingsSocket settings adminSocket adminApp | ||
where | ||
adminApp = admin appState conf | ||
|
||
-- | PostgREST admin application | ||
admin :: AppState.AppState -> AppConfig -> Wai.Application | ||
admin appState appConfig req respond = do | ||
isMainAppReachable <- any isRight <$> reachMainApp appConfig | ||
isMainAppReachable <- isRight <$> reachMainApp (AppState.getSocketREST appState) | ||
isSchemaCacheLoaded <- isJust <$> AppState.getSchemaCache appState | ||
isConnectionUp <- | ||
if configDbChannelEnabled appConfig | ||
|
@@ -53,35 +52,16 @@ admin appState appConfig req respond = do | |
-- Note that it doesn't even send a valid HTTP request, we just want to check that the main app is accepting connections | ||
-- The code for resolving the "*4", "!4", "*6", "!6", "*" special values is taken from | ||
-- https://hackage.haskell.org/package/streaming-commons-0.2.2.4/docs/src/Data.Streaming.Network.html#bindPortGenEx | ||
reachMainApp :: AppConfig -> IO [Either IOException ()] | ||
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 is no longer the case right? Will remove. |
||
reachMainApp AppConfig{..} = | ||
case configServerUnixSocket of | ||
Just path -> do | ||
sock <- socket AF_UNIX Stream 0 | ||
(:[]) <$> try (do | ||
connect sock $ SockAddrUnix path | ||
withSocketsDo $ bracket (pure sock) close sendEmpty) | ||
Nothing -> do | ||
let | ||
host | configServerHost `elem` ["*4", "!4", "*6", "!6", "*"] = Nothing | ||
| otherwise = Just configServerHost | ||
filterAddrs xs = | ||
case configServerHost of | ||
"*4" -> ipv4Addrs xs ++ ipv6Addrs xs | ||
"!4" -> ipv4Addrs xs | ||
"*6" -> ipv6Addrs xs ++ ipv4Addrs xs | ||
"!6" -> ipv6Addrs xs | ||
_ -> xs | ||
ipv4Addrs = filter ((/=) AF_INET6 . addrFamily) | ||
ipv6Addrs = filter ((==) AF_INET6 . addrFamily) | ||
|
||
addrs <- getAddrInfo (Just $ defaultHints { addrSocketType = Stream }) (T.unpack <$> host) (Just . show $ configServerPort) | ||
tryAddr `traverse` filterAddrs addrs | ||
reachMainApp :: Socket -> IO (Either IOException ()) | ||
reachMainApp appSock = do | ||
sockAddr <- getSocketName appSock | ||
sock <- socket (addrFamily sockAddr) Stream defaultProtocol | ||
try $ do | ||
connect sock sockAddr | ||
withSocketsDo $ bracket (pure sock) close sendEmpty | ||
where | ||
sendEmpty sock = void $ send sock mempty | ||
tryAddr :: AddrInfo -> IO (Either IOException ()) | ||
tryAddr addr = do | ||
sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) | ||
try $ do | ||
connect sock $ addrAddress addr | ||
withSocketsDo $ bracket (pure sock) close sendEmpty | ||
addrFamily (SockAddrInet _ _) = AF_INET | ||
addrFamily (SockAddrInet6 {}) = AF_INET6 | ||
addrFamily (SockAddrUnix _) = AF_UNIX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@develop7 Any concerns on windows? Maybe we should allow running tests on windows on CI to be extra sure (can be done on another PR).
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.
That'd be only fair, since Windows got first-class support
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.
We cannot enable all tests on Windows right off the bat, but specs & doctests should be fine