Repository: Flexget/Flexget

Issue:
Executing rpyc calls from client times out after 30 seconds
### Expected behaviour:
when running flexget execute one would expect that the command doesnt just fail because execution took longer then 30 seconds

### Actual behaviour:
execution fails due too rpyc 4.0.0 fixing their sync timeout code (previously didnt work)
this leads to misleading errors

### Steps to reproduce:
create a config file where execution takes longer then 30 seconds
run as a daemon
execute the config `flexget execute`
grab a beer :smile: 

#### Config:
<details>
 <summary>(click to expand)</summary>

```
tasks:
  Movies:
    exists_movie: 
      path: /mnt/raid/Movies
      lookup: imdb
      allow_different_qualities: better
    imdb_lookup: yes
    html:
      url: https://thepiratebay.org/top/207
      title_from: url
      links_re: [ magnet ]
    proper_movies: yes
    quality:
      - 1080p+
      - h264+
      - dvdrip+
    seen_movies:
      scope: local
    regexp:
      accept:
        - '2018'
        - '2017'
        - '2016'
        - '2015'
        - '2014'
        - 1080p
        - BRRip
        - DvdRip
        - BluRay
      reject:
        - Hindi
    template: 
      - deluge_settings
      - piratebay_manipulate

  TvShows:
    exists_series: 
      - /mnt/raid/TvShows/
      - /mnt/raid/Movies/
    template: deluge_settings
    series:
      shows:
        - 13 Reasons Why
        - Shooter
        - Silicon Valley
        - Mr Robot
        - Game of Thrones
        - Vikings
        - Wanted
        - This is us
        - Breaking Bad
        - Archer
        - Orphan Black
        - Narcos
        - House of Cards
        - Stranger Things
        - Wire
        - The Big Bang Theory
    discover:
      interval: 1 hour
      release_estimations: loose
      what:
        - next_series_episodes: yes
      from:
        - piratebay:
            category: highres tv
            sort_by: seeds  
    set:
      movedone: "/mnt/raid/TvShows/{{series_name}}/Season {{series_season}}/"
      path: "/mnt/raid/TvShows/{{series_name}}/Season {{series_season}}/"

templates:
  deluge_settings:
    deluge:
      username: localclient
      password: <hash>

  piratebay_html_search:
    html:
      url: https://thepiratebay.org/search/13 reasons why/0/3/0
      title_from: url
      links_re: [ magnet ]

  piratebay_manipulate:
    manipulate:
      - title:
          from: url
          extract: '&dn=(.*?)&tr=udp'
      - title:
          replace:
            regexp: '\+'
            format: ' '

schedules:
  - tasks: '*'
    interval:
      hours: 1

```

</details>
  
#### Log:
<details>
 <summary>(click to expand)</summary>

```
max@citadel:~$ flexget execute --debug --discover-now
There is a FlexGet process already running for this config, sending execution there.
2018-12-08 03:50 INFO     performance                   Enabling plugin and SQLAlchemy performance debugging
2018-12-08 03:50 VERBOSE  html          Movies          Requesting: https://thepiratebay.org/top/207
2018-12-08 03:50 VERBOSE  html          Movies          Response: 200 (OK)
2018-12-08 03:50 VERBOSE  details       Movies          Produced 100 entries.
...
...  # generic searching for torrents logs
...
2018-12-08 03:50 VERBOSE  details       Movies          Summary - Accepted: 0 (Rejected: 100 Undecided: 0 Failed: 0)
2018-12-08 03:50 VERBOSE  next_series_episodes TvShows         Series `Breaking Bad` with identified_by value `auto` are not supported. 
2018-12-08 03:50 VERBOSE  discover      TvShows         Discovering 15 titles ...
2018-12-08 03:50 INFO     discover      TvShows         Ignoring interval because of --discover-now
2018-12-08 03:50 INFO     task          TvShows         Plugin next_series_episodes has requested task to be ran again after execution has completed. Reason: Look for next season
2018-12-08 03:50 VERBOSE  discover      TvShows         Vikings S05E13 hasn't been released yet (Expected: 2018-12-12 00:00:00)
2018-12-08 03:50 VERBOSE  discover      TvShows         This is us S03E10 hasn't been released yet (Expected: 2019-01-15 00:00:00)
2018-12-08 03:50 VERBOSE  discover      TvShows         The Big Bang Theory S12E11 hasn't been released yet (Expected: 2019-01-10 00:00:00)
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/flexget/__init__.py", line 42, in main
    manager.start()
  File "/usr/lib/python3.7/site-packages/flexget/manager.py", line 344, in start
    client.handle_cli(self.args)
  File "/usr/lib/python3.7/site-packages/rpyc/core/netref.py", line 199, in __call__
    return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
  File "/usr/lib/python3.7/site-packages/rpyc/core/netref.py", line 75, in syncreq
    return conn.sync_request(handler, proxy, *args)
  File "/usr/lib/python3.7/site-packages/rpyc/core/protocol.py", line 471, in sync_request
    return self.async_request(handler, *args, timeout=timeout).value
  File "/usr/lib/python3.7/site-packages/rpyc/core/async_.py", line 95, in value
    self.wait()
  File "/usr/lib/python3.7/site-packages/rpyc/core/async_.py", line 47, in wait
    raise AsyncResultTimeout("result expired")
TimeoutError: result expired
```

</details>

### Additional information:

- FlexGet version:2.17.18.dev
- Python version:Python 3.7.1
- Installation method:AUR (compiled from git repo)
- Using daemon (yes/no):yes
- OS and version:Arch Linux


Discussion:

Resolving patch:
diff --git a/flexget/ipc.py b/flexget/ipc.py
--- a/flexget/ipc.py
+++ b/flexget/ipc.py
@@ -160,14 +160,15 @@ def shutdown(self):
 
 
 class IPCClient(object):
-    def __init__(self, port, password):
+    def __init__(self, port, password, sync_request_timeout=300):
         channel = rpyc.Channel(rpyc.SocketStream.connect('127.0.0.1', port))
         channel.send(password.encode('utf-8'))
         response = channel.recv()
         if response == AUTH_ERROR:
             # TODO: What to raise here. I guess we create a custom error
             raise ValueError('Invalid password for daemon')
-        self.conn = rpyc.utils.factory.connect_channel(channel, service=ClientService)
+        self.conn = rpyc.utils.factory.connect_channel(
+            channel, service=ClientService, config={'sync_request_timeout': sync_request_timeout})
 
     def close(self):
         self.conn.close()
diff --git a/flexget/manager.py b/flexget/manager.py
--- a/flexget/manager.py
+++ b/flexget/manager.py
@@ -336,7 +336,7 @@ def start(self):
             console('There is a FlexGet process already running for this config, sending execution there.')
             log.debug('Sending command to running FlexGet process: %s' % self.args)
             try:
-                client = IPCClient(ipc_info['port'], ipc_info['password'])
+                client = IPCClient(ipc_info['port'], ipc_info['password'], sync_request_timeout=self.options.timeout)
             except ValueError as e:
                 log.error(e)
             else:
diff --git a/flexget/options.py b/flexget/options.py
--- a/flexget/options.py
+++ b/flexget/options.py
@@ -406,6 +406,7 @@ def _debug_tb_callback(self, *dummy):
 manager_parser.add_argument('--cron', action=CronAction, default=False, nargs=0,
                             help='use when executing FlexGet non-interactively: allows background '
                                  'maintenance to run, disables stdout and stderr output, reduces logging level')
+manager_parser.add_argument('--timeout', default=300, help='number of seconds to run before timing out', type=int)
 
 
 class CoreArgumentParser(ArgumentParser):


Test patch: