Skip to content

Commit

Permalink
fix: forbid same server-port and admin-server-port
Browse files Browse the repository at this point in the history
Forbids server-port and admin-server-port from being equal altogether,
despite they might not conflict at all in case admin and app are bound
to different addresses. Implemented as per the discussion at
#3508 (comment)
  • Loading branch information
develop7 committed May 29, 2024
1 parent 9e6a89f commit 7d33ceb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #3533, #3536, Fix listener silently failing on read replica - @steve-chavez
+ If the LISTEN connection fails, it's retried with exponential backoff
- #3414, Force listener to connect to read-write instances using `target_session_attrs` - @steve-chavez
- #3508, Server port and admin server port can end up with the same value - @develop7
+ The app is fails to start when the server port and admin server port are the same

### Deprecated

Expand Down
11 changes: 10 additions & 1 deletion src/PostgREST/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,21 @@ readAppConfig dbSettings optPath prevDbUri roleSettings roleIsolationLvl = do
Left err ->
return . Left $ "Error in config " <> err
Right parsedConfig ->
Right <$> decodeLoadFiles parsedConfig
case processForbiddenValues parsedConfig of
Left err' ->
return . Left $ "Error in config " <> err'
Right config ->
Right <$> decodeLoadFiles config
where
-- Both C.ParseError and IOError are shown here
loadConfig :: FilePath -> IO (Either SomeException C.Config)
loadConfig = try . C.load

processForbiddenValues :: AppConfig -> Either Text AppConfig
processForbiddenValues cfg@AppConfig{..}
| configAdminServerPort == Just configServerPort = Left "admin-server-port cannot be the same as server-port"
| otherwise = Right cfg

decodeLoadFiles :: AppConfig -> IO AppConfig
decodeLoadFiles parsedConfig =
decodeJWKS <$>
Expand Down

0 comments on commit 7d33ceb

Please sign in to comment.