mrhappyasthma / IsThisStockGood

A tool for evaluating companies using the Rule #1 investing principles.
http://www.isthisstockgood.com
22 stars 10 forks source link

Crash can occur, but not sure on repro steps #47

Closed mrhappyasthma closed 2 years ago

mrhappyasthma commented 2 years ago
    data = fetchDataForTickerSymbol(ticker)
  File "D:\GitHub\Rule1-StockScreener\IsThisStockGood\src\DataFetcher.py", line 50, in fetchDataForTickerSymbol
    rpc.result()
  File "C:\Users\MrHappyAsthma\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\_base.py", line 432, in result
    return self.__get_result()
  File "C:\Users\MrHappyAsthma\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\_base.py", line 388, in __get_result
    raise self._exception
  File "C:\Users\MrHappyAsthma\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\MrHappyAsthma\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\MrHappyAsthma\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py", line 650, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "C:\Users\MrHappyAsthma\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "D:\GitHub\Rule1-StockScreener\IsThisStockGood\src\DataFetcher.py", line 204, in parse_morningstar_finances
    success = self.ratios.parse_finances(parsed_content.split('\n'))
AttributeError: 'NoneType' object has no attribute 'parse_finances'

Not exactly sure how it's possible to crash on this line: https://github.com/mrhappyasthma/IsThisStockGood/blob/master/src/DataFetcher.py#L204

When we ensure it's non-nil here: https://github.com/mrhappyasthma/IsThisStockGood/blob/master/src/DataFetcher.py#L202

mrhappyasthma commented 2 years ago

It's possible it's a race condition. I don't synchronize accesses/mutations of self.ratios.

mrhappyasthma commented 2 years ago

Testing a fix locally. I can't be positive if it's the fix, but running over 8000 queries to ensure it doesn't crash once.

mrhappyasthma commented 2 years ago

This seems like a potential preventative fix.

According to here, this may have been introduced by mutating the request headers: https://stackoverflow.com/a/20457621/1366973

Adding a simple lock seems to be reasonable fix, and have not yet witnessed the crash.