Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Zenbot sim stall/timeout in 4.1.0 unstable #2412

Closed
dlasher opened this issue Oct 1, 2020 · 12 comments · Fixed by #2425
Closed

Zenbot sim stall/timeout in 4.1.0 unstable #2412

dlasher opened this issue Oct 1, 2020 · 12 comments · Fixed by #2425

Comments

@dlasher
Copy link

dlasher commented Oct 1, 2020

  • Have I written custom code (as opposed to using zenbot vanilla): NO
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16/18/20 LTS
  • Zenbot version (commit ref, or version): 4.1.0
  • Zenbot branch: origin/unstable / origin/snyk-upgrade-4f21cbafbd4fd2773a1432ecfb3e348f
  • NodeJS version: v12.14.1
  • Python version (when using a python script): na
  • Exact command to reproduce (include everything):/zenbot.sh sim binance.BTC-USDT sim --period=10m --trend_ema=35 --enable_stats --debug --verbose --days 7
  • Did I make any changes to conf-sample.js?:

Describe the problem

git pulled most recent version 2 days ago, now "./zenbot.sh sim" does.. nothing.

thinking it was the mongodb, I repaired it. nada. destroyed it all, and backfilled again. nada. tried it on another machine. and another. Something broke SIM in current version, across multiple NODE versions (10/12/14) across multiple ubuntu version.

works:
./zenbot.sh trade binance.BTC-USDT --paper --period=10m --trend_ema=35 --enable_stats --debug --verbose --days 7
fetching pre-roll data:

binance.BTC-USDT saved 23349 trades 1 days left

stalls forever:
./zenbot.sh sim binance.BTC-USDT trade --paper --period=10m --trend_ema=35 --enable_stats --debug --verbose --days 7

fresh install vis git into new folder, changing NOTHING else. Stalls.

Source code / Error logs

no error log - it just sits for a good couple minutes, then returns to the prompt.

@dlasher dlasher changed the title Zenbot sim stall/timeout in 4.1.0 Zenbot sim stall/timeout in 4.1.0 unstable Oct 1, 2020
@dlasher
Copy link
Author

dlasher commented Oct 2, 2020

BTW, reading another thread, I see a reference to this older version of sim.js

https://raw.githubusercontent.com/DeviaVir/zenbot/660f1844b7df2a9cc586e57a580cb2e90cf43a3e/commands/sim.js

When I replace mine with that one, sim works again.

Not a huge diff, but worth looking at.

@dlasher
Copy link
Author

dlasher commented Oct 2, 2020

It's not really fixed.. lots of runs stall out/die - darwin backtester won't complete due to stalled sims. Something still wrong.

@tenaciousd93
Copy link

I've got the same problem too.
Fresh installation from yesterday with npm, unstable branch, on Mac OS 10.15.2 with npm 6.14.8 and node 12.18.4.
Tried to run update.sh but problem still there..

@brianunlam
Copy link
Contributor

brianunlam commented Oct 8, 2020

I've found the problem guys, if you go to engine.js and you comment line 761 the problem is solved.

if (!clock && so.mode !== 'live' && so.mode !== 'paper') clock = lolex.install({ shouldAdvanceTime: false, now: trade.time })

Using lolex is causing the issue.

I've tried replacing lolex with "@sinonjs/fake-timers": "^6.0.1", and it didn't solve the problem. Also I removed the use of async/await in sim.js, it didn't work either.

I don't want to create a PR removing lolex since I don't know how much it affects the simulation result due to my lack of experience with zenbot.

@brianunlam
Copy link
Contributor

brianunlam commented Oct 8, 2020

So, removing the use of lolex produced bad simulations. So it is not a solution at all, I updated my dockerfile to use node:12-alpine and it solved the problem and now simulations are making sense.
Later I will add a PR updating dockerfile and package.json to use node 12.

@dlasher
Copy link
Author

dlasher commented Oct 8, 2020

I'm using NVM, and have flipped back and forth between 10, 12, and 14, in some cases with a a full rm/git clone.. 12 seems to complain the least, but doesn't solve the problem, at least for me.

Fresh git pull, "nvm use lts/erbium (-> v12.18.4" npm install,
sim sits and never moves past first interval:


2020-09-30 16:15:50 0.0747600 XLM-USDT +0.12% 93508

@dlasher
Copy link
Author

dlasher commented Oct 8, 2020

I can confirm that commenting out line 761, as indicated above, DOES stop the stall, 100% of the time. Does make me very worried about the truth of the simulations however. 😞

end balance: 185109.51385183 (1751.09%)

Fairly unlikely. :(

@dlasher
Copy link
Author

dlasher commented Oct 8, 2020

tried lolex@5.1.2, 5.1.0, 4.1.0, 3.1.0, 2.1.0, 2.0.0, even 1.0.0 for fun, no change in behavior (other than 1.0.0 not working at all). Combined with @brianunlam 's work replacing it with fake-timers, I think it's probably not the lolex library, but some combination/way it's being invoked.

@brianunlam
Copy link
Contributor

brianunlam commented Oct 9, 2020

If you remove lolex the simulation doesn't work properly. The exact version of node is v12.18.4, please try that. @dlasher
I have many changes in my own branch. I will try to update unstable and see if it works.
Are you doing an npm install?
Update:
I moved to unstable branch, updated the dockerfile and it didn't work. I came back to my branch and it didn't work. I don't know dude.

@brianunlam
Copy link
Contributor

brianunlam commented Oct 9, 2020

@dlasher Finally I've found the problem. It was related to lolex.

Basically since version 3.6.2 mongodb replaced processWaitQueue with setImmediate.

lolex.install() is monkey patching setImmediate. So that is causing mongodb library to stall.

Here you can see more details about this:

mongodb/node-mongodb-native#2537
Screen Shot 2020-10-09 at 01 31 00

@brianunlam
Copy link
Contributor

It should solve the issue:

#2425

@dlasher
Copy link
Author

dlasher commented Oct 9, 2020

Grabbed the updated engine.js in #2425, put the "new" version of sim.js back in, and VOILA!!

Problem solved gentlemen!

Thank you, and well done!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants