Skip to content

refactor: make sure proper sockets cleanup is performed in App.run#5057

Merged
steve-chavez merged 1 commit into
PostgREST:mainfrom
mkleczek:push-kzmsoywqssow
Jul 6, 2026
Merged

refactor: make sure proper sockets cleanup is performed in App.run#5057
steve-chavez merged 1 commit into
PostgREST:mainfrom
mkleczek:push-kzmsoywqssow

Conversation

@mkleczek

@mkleczek mkleczek commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Right now code in App.run does not properly use bracket/finally to close sockets and clean-up mainSocketRef. This is not a big problem at the moment because the application is going to exit enyway but introducting proper resource handling will make future refactorings safer.

@mkleczek
mkleczek force-pushed the push-kzmsoywqssow branch 2 times, most recently from 8ba5b03 to e6c08d0 Compare June 29, 2026 11:59
Comment thread src/PostgREST/App.hs Outdated
@mkleczek
mkleczek force-pushed the push-kzmsoywqssow branch from e6c08d0 to a23182e Compare June 29, 2026 19:52
@steve-chavez

Copy link
Copy Markdown
Member

So on #5045, we added a socket close here:

onError adminSock ex = do
observer $ AdminServerCrashedObs ex
NS.close adminSock -- we close the socket so request doesn't hang

Which makes me wonder, should we move

runAdmin :: AppState -> Maybe NS.Socket -> IO (Maybe NS.Socket) -> Warp.Settings -> IO ()
runAdmin appState maybeAdminSocket getSocketREST settings = do

To App.hs so we can have all the logic about opening/closing sockets centralized and visible?

@mkleczek

Copy link
Copy Markdown
Collaborator Author

Which makes me wonder, should we move

runAdmin :: AppState -> Maybe NS.Socket -> IO (Maybe NS.Socket) -> Warp.Settings -> IO ()
runAdmin appState maybeAdminSocket getSocketREST settings = do

To App.hs so we can have all the logic about opening/closing sockets centralized and visible?

That would make Admin module really unnecessary, I'd say.

Not opposing this but I'd say this should be a separate refactoring PR.

I also think we should go even further and "pull up" main thread id from AppState - but, again, in a separate PR.

@taimoorzaeem

Copy link
Copy Markdown
Member

That would make Admin module really unnecessary, I'd say.

Not opposing this but I'd say this should be a separate refactoring PR.

Agreed.

Comment thread src/PostgREST/App.hs
@mkleczek

mkleczek commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator Author

Which makes me wonder, should we move

runAdmin :: AppState -> Maybe NS.Socket -> IO (Maybe NS.Socket) -> Warp.Settings -> IO ()
runAdmin appState maybeAdminSocket getSocketREST settings = do

To App.hs so we can have all the logic about opening/closing sockets centralized and visible?

See #5076

That would make Admin module really unnecessary, I'd say.

Not opposing this but I'd say this should be a separate refactoring PR.

I also think we should go even further and "pull up" main thread id from AppState - but, again, in a separate PR.

See #5056

@steve-chavez @taimoorzaeem

Right now code in App.run does not properly use bracket/finally to close sockets and clean-up mainSocketRef. This is not a big problem at the moment because the application is going to exit enyway but introducting proper resource handling will make future refactorings safer.
@mkleczek
mkleczek force-pushed the push-kzmsoywqssow branch from a23182e to 7b500b3 Compare July 6, 2026 06:12
@steve-chavez
steve-chavez merged commit c5c9dc3 into PostgREST:main Jul 6, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants