Cinderella-Man / hands-on-elixir-and-otp-cryptocurrency-trading-bot-source-code

Resources related to the "Hands-on Elixir & OTP: Cryptocurrency trading bot" book
https://elixircryptobot.com
75 stars 24 forks source link

SSL problems at startup? #6

Closed kamidev closed 3 years ago

kamidev commented 3 years ago

When I recently tried your code under Elixir 1.12, I had SSL problems that prevented iex -S mix from running (see stack trace below). Even worse, when I tried using 1.11 I had the same problem.

Have you had any similar problems with SSL?

¨¨ Ranch listener SurveyAPIWeb.Endpoint.HTTPS had connection process started with :cowboy_tls:start_link/4 at #PID<0.454.0> exit with reason: {:undef, [{:ssl, :ssl_accept, [{:sslsocket, {:gen_tcp, #Port<0.22>, :tls_connection, [option_tracker: #PID<0.346.0>, session_tickets_tracker: :disabled, session_id_tracker: #PID<0.347.0>]}, [#PID<0.452.0>, #PID<0.451.0>]}, [], 5000], []}, {:ranch_ssl, :handshake, 3, [file: '/Users/jonas/ex/survey_api/deps/ranch/src/ranch_ssl.erl', line: 142]}, {:ranch, :handshake, 2, [file: '/Users/jonas/ex/survey_api/deps/ranch/src/ranch.erl', line: 243]}, {:cowboy_tls, :connection_process, 4, [file: '/Users/jonas/ex/survey_api/deps/cowboy/src/cowboy_tls.erl', line: 43]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}] ¨¨

kamidev commented 3 years ago

In the end, I fixed this by setting the "binance_mock" project to use the same Elixir version as the other umbrella projects. Then I updated "binance" and "websockex" libraries to the latest version everywhere and rebuilt. This worked for both Elixir 1.11 and the latest Elixir 1.12-rc version.

I have checked in branches "elixir_1.11" and "elixir_1.12" at https://github.com/kamidev/create-a-cryptocurrency-trading-bot-in-elixir-source-code that show this. Erlang and Elixir are installed with asdf, so I can easily make compilation use the expected Erlang and Elixir versions.

Cinderella-Man commented 3 years ago

Hello again :slightly_smiling_face:

2nd time today :stuck_out_tongue: some people indeed pointed out that there's an issue with the SSL certificates and I realized that the binance module could be the culprit as it was using "deprecated" v1 APIs. I updated the binance package to use v3 (besides a single endpoint that still uses v1 as it's not backward compatible). I think I can see my mistake - I left the un-updated mix.lock file which uses an old version of the binance module.

Regards the Elixir versions - those are autogenerated(I can update them without updating the book) and as far as I understand they should allow anything "above" specified versions up to (and excluding) 2.0, which shouldn't have any impact on the usage?

~> 1.10 means >= 1.10.0 and < 2.0.0

So this should be fixed after just mix deps.update --all without changing anything else? (I will then push the updated mix.lock file to the repo)

kamidev commented 3 years ago

Yes, a lock file prevented a necessary update. Dependencies in umbrella projects can be annoying that way. Nice that you found it!

In this case, updating the libraries does work independent of Erlang/Elixir version. But there will be a new major versions soon. And I have seen funny SSL things when upgrading before. So I occasionally run code with specific combinations of Erlang and Elixir to see how my dependencies are doing.

kamidev commented 3 years ago

I cloned a new repo. Chapter_15 now build and run without SSL errors our of the box. Works the same for Elixir 11 and 12.

Cinderella-Man commented 3 years ago

Thank you very very very much for double-checking this :+1: I updated the mix.lock in all the branches - this should take care of the SSL issues once and for all :crossed_fingers: (at least until Binance will deprecate v3 :wink: )

I also added an interface to publish data via DataWarehouse so you don't need to call start_link/1 - update to the book will follow: https://github.com/frathon/create-a-cryptocurrency-trading-bot-in-elixir-source-code/commit/8308e5115265e2e845e2c305ed5ebbc63801c4e5

Thank you once again for your efforts - seriously, really appreciate :pray: