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

proposal: net/http: add Unregister method to ServeMux #50056

Closed
rgooch opened this issue Dec 9, 2021 · 8 comments
Closed

proposal: net/http: add Unregister method to ServeMux #50056

rgooch opened this issue Dec 9, 2021 · 8 comments

Comments

@rgooch
Copy link

rgooch commented Dec 9, 2021

Currently it is not possible to dynamically register and deregister path handlers with a ServeMux object. Once a handler for a path is registered, it cannot be changed or removed.
Solutions to work around this (such as wrapping ServeMux) can lead to a growing map containing stale handlers.

The proposal is to add an Unregister method with the following function signature:
func (mux *ServeMux) Unregister(pattern string)

@rgooch rgooch added the Proposal label Dec 9, 2021
@gopherbot gopherbot added this to the Proposal milestone Dec 9, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Dec 9, 2021
@ianlancetaylor
Copy link
Contributor

CC @neild @bradfitz

@earthboundkid
Copy link
Contributor

Seems extremely racey.

If you need this functionality, why not just register a handler for / and then mux it yourself at runtime? I don't think this fits into the usecase for the standard serve mux, and it's very easy to write your own, so I would be opposed to any performance hit that would come from checking a lock at runtime.

@rgooch
Copy link
Author

rgooch commented Dec 9, 2021

The internal locking protects against basic races.
Creating a custom mux doesn't work well with libraries that use DefaultServeMux.

@neild
Copy link
Contributor

neild commented Dec 9, 2021

I don't think this is generally useful enough to warrant adding, and I suspect that a need to unregister handlers from a ServeMux points at a deeper design issue somewhere. For example, a library which is hardcoded to use http.DefaultServeMux depends on shared global state.

@rsc
Copy link
Contributor

rsc commented Dec 15, 2021

The design of ServeMux is intentionally order-independent, so that if you have things registered from init functions, it doesn't matter what order the init functions run. I'm very wary of adding something that would introduce order dependence in this API.

There are many other options if you need this functionality, of course, including writing a trivial custom mux.

@rsc
Copy link
Contributor

rsc commented Dec 15, 2021

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Active in Proposals (old) Dec 15, 2021
@rsc
Copy link
Contributor

rsc commented Jan 5, 2022

Based on the discussion above, this proposal seems like a likely decline.
— rsc for the proposal review group

@rsc rsc moved this from Active to Likely Decline in Proposals (old) Jan 5, 2022
@rsc rsc moved this from Likely Decline to Declined in Proposals (old) Jan 12, 2022
@rsc
Copy link
Contributor

rsc commented Jan 12, 2022

No change in consensus, so declined.
— rsc for the proposal review group

@rsc rsc closed this as completed Jan 12, 2022
@golang golang locked and limited conversation to collaborators Jan 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

6 participants