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

Add/remove routes at runtime #1100

Open
arghness opened this issue Oct 21, 2022 · 3 comments
Open

Add/remove routes at runtime #1100

arghness opened this issue Oct 21, 2022 · 3 comments

Comments

@arghness
Copy link

I started writing a thread-safe wrapper for Router / Private::RouterHandler to support adding and removing routes dynamically, when I saw in the RouterHandler comments:

            /**
             * Used for mutable router. Useful if it is required to
             * add/remove routes at runtime.
             * \param[in] router Pointer to a (mutable) router.
             */
            explicit RouterHandler(std::shared_ptr<Rest::Router> router);

I wondered how this might be done safely, once the server is running? Can it only be done when processing a request on a single-threaded server?

@chorfa007
Copy link

The same problem like you i used the API Routes::Remove but i still access to the server after removing routes in many use case the application crash due an issue of bind ...

@arghness
Copy link
Author

arghness commented Nov 1, 2022

The same problem like you i used the API Routes::Remove but i still access to the server after removing routes in many use case the application crash due an issue of bind ...

I'm pretty sure that's still not thread safe, it still just calls the methods on Router / Private::RouterHandler, so you'll run in to issues unless you're very careful.

I'm not entirely sure if my wrappers are fully thread-safe, but they seem okay so far.

@dennisjenkins75
Copy link
Collaborator

I've not looked at the code, but I suspect that you are correct. Adding and removing routes is likely not thread safe; it should take a writer lock on the routing table, and doing route lookups should take a reader lock. This locking is likely non-existent.

You can probably verify this with valgrind --fair-sched=yes ${your_program}.

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

3 participants