Skip to content

Conversation

jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Apr 15, 2012

This is a cleaned up version of JoelKatz' work, originally found in pull request #568.

A few minor didnt-check-error-return bugs were fixed. All other changes were comment- or coding style-related changes unrelated to behavior.

Should be upstream-ready at this point. Is in use at a few pools and other places.

@luke-jr
Copy link
Member

luke-jr commented Apr 15, 2012

Note this is missing some important thread-safety issues I had cleaned up in #568 (which has been upstream-ready for months)

@jgarzik
Copy link
Contributor Author

jgarzik commented Apr 15, 2012

Nothing is -missing-. There is a lock across the entirety of the RPC command execution.

@luke-jr
Copy link
Member

luke-jr commented Apr 15, 2012

Ah, okay... that's what I missed when comparing the two.

@gavinandresen
Copy link
Contributor

Any limit to the number of threads spawned? Could somebody out-of-memory DoS if they just keep connecting to the RPC port a gazillion times and never closing the connections?

@luke-jr
Copy link
Member

luke-jr commented Apr 15, 2012

I suspect you'd hit PID limits before memory, and socket limits before that. And since bitcoind uses select(), it would randomly corrupt memory. But that's already a problem anyway... :/

@jgarzik
Copy link
Contributor Author

jgarzik commented Apr 15, 2012

There is no limit to the threads spawned -- but note that threads are spawned only after checking the IP filter list.

The first resource likely to be exhausted is a thread-group or systemwide thread limit, not memory. But yes, if you pass the IP filter list, that can be DoS'd.

Should not be a problem to add a simple simultaneous-threads limit here, though.

@gavinandresen
Copy link
Contributor

ACK. I assume the main benefit right now is the keepalive to save constant connection setup/teardown, since RPC calls will still be essentially single-threaded due to obtaining the cs_main and wallet locks. And the secondary benefit is we can eventually move to more fine-grained locks...

@gavinandresen
Copy link
Contributor

Anybody else getting a compiler warning:
src/bitcoinrpc.cpp:2618: warning: suggest a space before ‘;’ or explicit braces around empty body in ‘while’ statement [-Wempty-body]

@jgarzik
Copy link
Contributor Author

jgarzik commented Apr 22, 2012

Rebased. @gavinandresen do you still get a warning?
If yes, can you paste the code line as well as the warning, just for double-checking?

@gavinandresen
Copy link
Contributor

Still getting an error:

bitcoinrpc.cpp: In function ‘void ThreadRPCServer3(void*)’:
bitcoinrpc.cpp:2610: warning: suggest a space before ‘;’ or explicit braces around empty body in ‘while’ statement

Line 2610 is:
while (0);

... which looks to me like it should be deleted, since loop is defined as: for(;;) in util.h

@jgarzik
Copy link
Contributor Author

jgarzik commented Apr 24, 2012

@gavinandresen fixed. Merge error added some useless code.

@gavinandresen
Copy link
Contributor

Testing this, I got a crash on shutdown of Bitcoin-Qt; see
https://gist.github.com/2480177

}
}
catch (Object& objError)
{
ErrorReply(stream, objError, id);
ErrorReply(conn->stream, objError, id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be setting fRun to false also? (#1075 removes the first try block entirely, letting this handle errors)

JoelKatz added 2 commits May 8, 2012 20:11
Change internal HTTP JSON-RPC server from single-threaded to
thread-per-connection model.  The IP filter list is applied prior to starting
the thread, which then processes the RPC.

A mutex covers the entire RPC operation, because not all RPC operations are
thread-safe.

[minor modifications by jgarzik, to make change upstream-ready]
@jgarzik
Copy link
Contributor Author

jgarzik commented May 9, 2012

Rebased, and updated for recent table-driven RPC dispatch. That change simplified our error handling, here.

jgarzik pushed a commit that referenced this pull request May 11, 2012
Multithreaded JSON-RPC with HTTP 1.1 Keep-Alive support
@jgarzik jgarzik merged commit b34c5f3 into bitcoin:master May 11, 2012
coblee pushed a commit to litecoin-project/litecoin that referenced this pull request Jul 17, 2012
Multithreaded JSON-RPC with HTTP 1.1 Keep-Alive support
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 22, 2019
Added cash denomination per BUIP087
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants