Update dependency in interactive session (IEx)

Hi,

Recently I tried to update a dependency (:hackney) since they got a bug regarding OTP 23 and the ssl versions. I am using elixir/phoenix in a container, and I achieved to attach an IEx to the instance in the running container. Also, I was able to use mix command in the container, correctly updating the libraries in the file system.

First question: why I needed to remove the directory _build/prod/lib/hackney and deps/hackney to be able to fetch the latest version correctly? What was I doing wrong? What would be the correct way?

I did many trials with lines like this:

mix deps.update hackney
# some warning about rebar3 version (update)
mix local.rebar
mix deps.get hackney
mix deps.clean hackney
mix deps.update hackney
mix deps.compile hackney
rm -rf _build/prod/lib/hackney
rm -rf deps/hackney
mix deps.get hackney
mix deps.update hackney
mix deps.compile hackney
mix

# Also, in another node I did directly this:
rm -rf _build
mix deps.update hackney
mix deps.get
mix deps.compile

After such lines, I could see in deps the correct latest hackney version (1.17.2), but I felt I was doing something wrong repeating so many steps without understanding the purpose of executing manually rm -rf and such.

Second question: How can I update the dependency for the running elixir/phoenix application without restart the elixir process, neither the container?

After the above steps, I attach to the instance with IEx, and trying these sentences:

> Application.spec(:hackney, :vsn)
'1.15.2'
> recompile
:ok
# recompiles but at the end, the same version (not the 1.17.2 present in the filesystem)
> Application.spec(:hackney, :vsn)
'1.15.2'
> r :hackney
# could not find source (/tmp/build/deps/hackney/src/hackney.erl) for module: :hackney
# IEx.Helpers.do_r/1

If I exit the IEx and copy manually that dependency in tmp:

mkdir -p /tmp/build/deps
cp -r deps/hackney /tmp/build/deps/

Then, in IEx again:

> recompile
:noop
> r :hackney
/tmp/build/deps/hackney/src/hackney.erl:40: can't find include file "hackney.hrl"
/tmp/build/deps/hackney/src/hackney.erl:41: can't find include file "hackney_lib.hrl"
/tmp/build/deps/hackney/src/hackney.erl:45: record hackney_url undefined
/tmp/build/deps/hackney/src/hackney.erl:48: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:57: record hackney_url undefined
/tmp/build/deps/hackney/src/hackney.erl:58: record hackney_url undefined
/tmp/build/deps/hackney/src/hackney.erl:61: variable 'Host' is unbound
/tmp/build/deps/hackney/src/hackney.erl:61: variable 'Port' is unbound
/tmp/build/deps/hackney/src/hackney.erl:61: variable 'Transport' is unbound
/tmp/build/deps/hackney/src/hackney.erl:135: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:141: variable 'Method' is unbound
/tmp/build/deps/hackney/src/hackney.erl:143: variable 'Transport' is unbound
/tmp/build/deps/hackney/src/hackney.erl:144: variable 'Socket' is unbound
/tmp/build/deps/hackney/src/hackney.erl:305: record hackney_url undefined
/tmp/build/deps/hackney/src/hackney.erl:319: record hackney_url undefined
/tmp/build/deps/hackney/src/hackney.erl:325: variable 'User' is unbound
/tmp/build/deps/hackney/src/hackney.erl:330: variable 'Password' is unbound
/tmp/build/deps/hackney/src/hackney.erl:335: variable 'Host' is unbound
/tmp/build/deps/hackney/src/hackney.erl:335: variable 'Port' is unbound
/tmp/build/deps/hackney/src/hackney.erl:335: variable 'Transport' is unbound
/tmp/build/deps/hackney/src/hackney.erl:365: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:368: record client undefined
...
/tmp/build/deps/hackney/src/hackney.erl:859: variable 'Port' is unbound
/tmp/build/deps/hackney/src/hackney.erl:859: variable 'Transport' is unbound
/tmp/build/deps/hackney/src/hackney.erl:859: variable 'Host' unsafe in 'case' (line 811)
/tmp/build/deps/hackney/src/hackney.erl:860: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:879: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:881: variable 'T' is unbound
/tmp/build/deps/hackney/src/hackney.erl:886: variable 'Path' is unbound
/tmp/build/deps/hackney/src/hackney.erl:886: variable 'Path' is unbound
/tmp/build/deps/hackney/src/hackney.erl:892: record hackney_url undefined
/tmp/build/deps/hackney/src/hackney.erl:938: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:944: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:946: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:948: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:949: variable 'Ref' is unbound
/tmp/build/deps/hackney/src/hackney.erl:951: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:953: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:954: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:957: variable 'Ref' is unbound
/tmp/build/deps/hackney/src/hackney.erl:961: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:963: variable 'Ref' is unbound
/tmp/build/deps/hackney/src/hackney.erl:972: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:986: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:995: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:997: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:999: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1001: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1003: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1005: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1007: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1009: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1011: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1013: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:1015: record client undefined
/tmp/build/deps/hackney/src/hackney.erl:821: Warning: variable 'Opts' is unused
/tmp/build/deps/hackney/src/hackney.erl:843: Warning: variable 'NewRedirect' is unused
/tmp/build/deps/hackney/src/hackney.erl:859: Warning: variable 'NewRedirect' is unused
/tmp/build/deps/hackney/src/hackney.erl:881: Warning: variable 'Scheme' is unused
/tmp/build/deps/hackney/src/hackney.erl:882: Warning: variable 'NewPath' is unused
/tmp/build/deps/hackney/src/hackney.erl:996: Warning: variable 'Async' is unused
/tmp/build/deps/hackney/src/hackney.erl:998: Warning: variable 'Pid' is unused
/tmp/build/deps/hackney/src/hackney.erl:1000: Warning: variable 'Follow' is unused
/tmp/build/deps/hackney/src/hackney.erl:1002: Warning: variable 'Force' is unused
/tmp/build/deps/hackney/src/hackney.erl:1004: Warning: variable 'Max' is unused
/tmp/build/deps/hackney/src/hackney.erl:1008: Warning: variable 'Dynamic' is unused
/tmp/build/deps/hackney/src/hackney.erl:1010: Warning: variable 'WithBody' is unused
/tmp/build/deps/hackney/src/hackney.erl:1014: Warning: variable 'MaxBody' is unused
** (CompileError)  compile error
    (iex 1.11.3) lib/iex/helpers.ex:1185: IEx.Helpers.compile_erlang/1
    (iex 1.11.3) lib/iex/helpers.ex:433: IEx.Helpers.do_r/1
    (iex 1.11.3) lib/iex/helpers.ex:415: IEx.Helpers.r/1

So, I am at a loss trying to update the dependency at runtime.