Skip to content

Commit

Permalink
LocalRPC: add --timeout arg
Browse files Browse the repository at this point in the history
To allow running local rpc commands that might take a very long time.
The server-side `processing_timeout` is a bit ugly though... :/
  • Loading branch information
SomberNight committed Apr 28, 2022
1 parent 265a5a8 commit 5f4dd2c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions electrumx/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,8 @@ def set_request_handlers(self, ptuple):
class LocalRPC(SessionBase):
'''A local TCP RPC server session.'''

processing_timeout = 10**9 # disable timeouts

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.client = 'RPC'
Expand Down
6 changes: 5 additions & 1 deletion electrumx_rpc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def main():
)
main_parser.add_argument('-p', '--port', metavar='port_num', type=int,
help='RPC port number')
main_parser.add_argument('--timeout', type=int, default=30,
help='timeout for command in seconds')

subparsers = main_parser.add_subparsers(help='sub-command help',
dest='command')
Expand All @@ -110,13 +112,15 @@ def main():
if port is None:
port = int(environ.get('RPC_PORT', 8000))
method = args.pop('command')
timeout = args.pop('timeout')

# aiorpcX makes this so easy...
async def send_request():
try:
async with timeout_after(30):
async with timeout_after(timeout):
async with connect_rs('localhost', port) as session:
session.transport._framer.max_size = 0
session.sent_request_timeout = timeout
result = await session.send_request(method, args)
if method in ('query', ):
for line in result:
Expand Down

0 comments on commit 5f4dd2c

Please sign in to comment.