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

[Feature] Enable http-keepalives/HTTP2 on JSON-RPC interface! #384

Merged
merged 1 commit into from
Jul 22, 2020

Conversation

zquestz
Copy link
Contributor

@zquestz zquestz commented Jul 17, 2020

Enable support for http-keepalive's on the JSON-RPC interface. In addition we gain HTTP2 support by getting rid of the hijack code!

I have tested this extensively and it works great with curl/wget/bchctl. I also was able to mitigate the issue that required the hijack code. By setting the ReadHeaderTimeout it can check the RPC auth and then allow an auth'd client to use the ReadTimeout for long poll requests.

I also updated the code to use the built in http CloseNotifier.

Fixes: #380

@cculianu
Copy link

Hmm I just tried it. I telnetted to it and hand-crafted the header & request.. After issuing it a few "server.pings" in succession I consistently get a panic. I also tried Fulcrum and it started the synch process only for bchd to also panic immediately.

This is the stack trace each time, same trace:

panic: net/http: CloseNotify called after ServeHTTP finished

goroutine 8783 [running]:
net/http.(*response).CloseNotify(0xc0006d61c0, 0x1be0160)
	/opt/local/lib/go/src/net/http/server.go:1972 +0x5e
main.(*rpcServer).jsonRPCRead.func1(0x1be0160, 0xc0006d61c0, 0xc01173b4a0)
	/Users/calin/src/bchd/rpcserver.go:4275 +0x55
created by main.(*rpcServer).jsonRPCRead
	/Users/calin/src/bchd/rpcserver.go:4274 +0x153

@zquestz
Copy link
Contributor Author

zquestz commented Jul 17, 2020

Status update, appears to be working. No more panics. =)

@cculianu
Copy link

Awesome. One more thing not related to this change -- the other bitcoind's expect a boolean value for getrawmempool's first argument, but bchd panics if it is a boolean and complains about expecting int:

{"error":{"code":-8,"message":"Failed to parse request: parameter #2 'verbose' must be type int (got bool)"},"id":168,"jsonrpc":"1.0","result":null}

Shall I open an issue for this?

@cculianu
Copy link

Oh.. I see. This is not an issue. I had the bitcoind RPCQuirks variable set in the bchd.conf. Weird. I grepped for that and found no mention of it in the codebase. If the variable is not set, this error goes away.

@cculianu
Copy link

Oh no.. my bad. Error still happens. Weird. So getrawmempool's first arg (verbose arg) is a boolean, true/false, but getrawtransaction's second arg (also boolean true/false) expects an int. :(

rpcserver.go Outdated Show resolved Hide resolved
@zquestz
Copy link
Contributor Author

zquestz commented Jul 17, 2020

Awesome. One more thing not related to this change -- the other bitcoind's expect a boolean value for getrawmempool's first argument, but bchd panics if it is a boolean and complains about expecting int:

{"error":{"code":-8,"message":"Failed to parse request: parameter #2 'verbose' must be type int (got bool)"},"id":168,"jsonrpc":"1.0","result":null}

Shall I open an issue for this?

Wait, it panics or just returns an error?

@zquestz
Copy link
Contributor Author

zquestz commented Jul 17, 2020

Yeah... getrawtransaction takes 2 args, one is the tx id, then verbose flag which is indeed an int. However, what worries me is that you are seeing panics... trying to replicate that now.

@zquestz
Copy link
Contributor Author

zquestz commented Jul 17, 2020

So the only thing I am really worried about here is the panic's you reported that I can't replicate. I was curling my node and can't simulate any panics. If I pass the wrong type it complains but does not crash the process. Can you share a call that causes the panic?

@zquestz zquestz force-pushed the experimental-http-keepalive branch from c617f38 to c196d09 Compare July 17, 2020 22:21
@zquestz zquestz changed the title [WIP][Feature] Enable http-keepalives on JSON-RPC interface! [Feature] Enable http-keepalives on JSON-RPC interface! Jul 18, 2020
@zquestz zquestz requested review from cpacia and tyler-smith July 18, 2020 01:44
@zquestz
Copy link
Contributor Author

zquestz commented Jul 18, 2020

NOTE: there were no panics, @cculianu was just saying it threw an error. Nothing to worry about crashing wise. =)

@zquestz zquestz force-pushed the experimental-http-keepalive branch from b1f6cee to d1da409 Compare July 18, 2020 02:49
@cculianu
Copy link

cculianu commented Jul 18, 2020

@zquestz Yeah sorry for using the panic word in a panicky way. I meant the English sense of the word. I hardly program much Go so to me that word has no special panic-inducing connotation associated with it....

@cculianu
Copy link

cculianu commented Jul 18, 2020

BTW I have been running Fulcrum connected to bchd for hours now in a test and after setting the ping timer (on the Fulcrum side) to something like 3 seconds (paranoia).. it never drops conn now due to idle.. and it works very fast. This is off the latest commit as of the time of this writing: d1da409

I'm all-for this feature!

@cculianu
Copy link

Do you think there's a strong chance this change (or something equivalent) will make it into mainline bchd? I want to bullet-point in my next fulcrum release that "bchd support is ready!"... but I don't know if that's premature as of now.

Thanks.

@zquestz zquestz changed the title [Feature] Enable http-keepalives on JSON-RPC interface! [Feature] Enable http-keepalives/HTTP2 on JSON-RPC interface! Jul 21, 2020
@cpacia cpacia merged commit 46b53ee into master Jul 22, 2020
@cpacia cpacia deleted the experimental-http-keepalive branch March 16, 2021 17:25
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

Successfully merging this pull request may close these issues.

Implement persistent connections for HTTP RPC (JSON)
3 participants