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

Ability for app to recover from an unavailable socket #2119

Open
bsupnik opened this issue Aug 7, 2024 · 3 comments
Open

Ability for app to recover from an unavailable socket #2119

bsupnik opened this issue Aug 7, 2024 · 3 comments

Comments

@bsupnik
Copy link

bsupnik commented Aug 7, 2024

Our app (X-Plane) embeds Drogon to provide a restful API for third party add-ons. When the listening port for API requests is not available (e.g. because it is in use or some other machine-specific failure causes ::bind to fail) Trantor calls exit(), terminating the entire app.

We would like to receive an error code from the attempt to create the listener so we can alert the user that web end points are not available and continue app launch.

We can code this ourselves! I have two questions:

  1. Would this kind of recoverability be desirable as a core feature of Drogon? E.g. should we create a pull request?
  2. If it is desirable, do you have a preference for how the recovery path is implemented?

From a brief look at the code, it looks like we could potentially throw an exception out of the "acceptor" constructor if bind fails, and eventually catch it where the listener shared ptr is created. Is the Drogon code base meant to be exception safe, or exception free (meaning, like, don't use them)?

The alternative non-exception implementation would be to have the state of the socket be visible (through the layers of objects) such that the listener-creating code could ask (after creating the listener) "did this thing init successfully, or is it a zombie", and then throw it out if it failed.

@an-tao
Copy link
Member

an-tao commented Aug 8, 2024

@bsupnik Thanks for your feedback. Initially, the design of the Drogon framework tried to avoid using exceptions. However, as complexity increased, exceptions were eventually introduced. Therefore, using exceptions instead of directly exiting is a good choice. You are welcome to create a PR to provide a patch.

@bsupnik
Copy link
Author

bsupnik commented Aug 8, 2024

Thanks for the guidance - we'll put together a prototype and get a draft PR put together.

@an-tao
Copy link
Member

an-tao commented Aug 9, 2024

@bsupnik I noticed that X-Plane is a very famous flight simulation software. Would you be willing to share your project in #1878 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants