-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
node: serve JSON-RPC on all unused HTTP paths #21826
Conversation
…ll result in "invalid request" string, but 200 code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm at first blush but am just checking it in my phone atm. One thing I like is this completely removes the .RequestURI comparison which I also noticed was causing query strings to fail to route to the RPC server (e.g. a POST to /?foo=bar
would 404).
My only concern is if sending to the mux first as a precheck beforehand has any sort of performance regression, I'll try out this change in the morning and see if it has any obvious change it performance/pprof on one of our canary nodes.
I ran a mix of random state-related RPCs from a sample of production traffic against our slightly forked version of geth both without and with this patch applied, and actually your PR ran faster than the old one: Baseline:
With this PR merged in:
Anyways I think the key takeaway is that this definitely does not have any appreciable negative impact on RPC performance. I suspect the speed boost was due to the short nature of the test and the distinct possibility that the node was processing more complex blocks or devp2p traffic or what not during the first run. So in short great work @renaynay and lgtm! Thanks @holiman for letting me know about this PR, it'll be one less patch for us to keep in our fork going forward. |
This is great to hear, thanks for the information @ryanschneider |
We discussed this a bit last couple days, and I'm not super happy to include this change. It does work, but the behavior also gets a bit unpredictable. For example, if you enable GraphQL, JSON-RPC will not be served on I think it would be better to restrict JSON-RPC to a single path. @ryanschneider AFAIK, your issue with this was mostly that AWS load balancing does not support changing the path. Can you give us some insight where the path is coming from in your case? I'm hoping it can be solved in a different way. |
Without going too deep into specifics, we have multiple groups of nodes behind a single load balancer. While this isn't exactly how we are setup, imagine that some of our mainnet archive nodes are on a URL like It could be worked around by running a separate local reverse proxy on the node (e.g. nginx with a rewrite rule) but that seems like a lot of extra devops surface when we already have a proxy in front of the internal ALB in our stack. Or we could work around the ALB limitation by using Host headers or DNS names instead of URL paths. The issue isn't really that there aren't other ways to do it, it's that having geth behave like it did before .12 is the least significant change, though I do understand your concern about unexpected behavior. What about a compromise where the "any path" behavior only works if |
@fjl or @renaynay any thoughts on this compromise approach #21826 (comment) ?
|
Sorry for not replying, still thinking about this. |
I have a better idea. Instead of serving JSON-RPC requests on all unmatched paths, we can add a flag that lets you set the path of the RPC handler (or path prefix, if necessary). @ryanschneider this would solve your case, since the path is specific to each geth instance, right? |
@fjl ya that would work. We would probably run with a wildcard prefix like |
Okay sounds good. On holiday now but will implement this ASAP. |
Awesome, so I'm not 100% familiar with this code but I think that this approach can actually lead to a simpler codebase, since the cleanest thing to do would probably be "register" the Graph QL, GraphQL UI, HTTP JSONRPC and Websocket JSONRPC handlers all the same way, which could allow |
Option 1: https://github.com/renaynay/go-ethereum/pull/31/files |
Closing in favor of #22184 |
) This change allows users to set a custom path prefix on which to mount the http-rpc or ws-rpc handlers via the new flags --http.rpcprefix and --ws.rpcprefix. Fixes #21826 Co-authored-by: Felix Lange <fjl@twurst.com>
This PR fixes an issue where an RPC call that is not on the root path results in a 404 Not Found error. Instead, the request will be pattern-matched against the mux router to see if any registered paths match the request path, and if not, the server will fall back to JSON-RPC. This will allow RPC requests with an additional path to still be served.