Calling DBConnection.disconnect_all with intervals above 4294 does not disconnect on checkin as expected, and as documented. With intervals above this value, the connection will only disconnect once it has become idle.
The reason for this is that we call :erlang.phash2, passing it the "erlang native time" representation of the interval. :erlang.phash2 has a max input value of 2^32, and 2^32 "erlang native time units" corresponds to 4294 milliseconds.
I'm aware that "native time units" can be OS dependent. I've tested this on my local development environment (macOS 12.6) and our staging environment (Alpine linux), and both return the same value for
When calling :erlang.phash2, we don't really need native time resolution, we could just convert to milliseconds when calling phash2, then convert back to native time units.
Please see https://github.com/whilefalse/disconnect_all for full reproduction information and more details.
Brief overview
Calling
DBConnection.disconnect_all
with intervals above4294
does not disconnect on checkin as expected, and as documented. With intervals above this value, the connection will only disconnect once it has become idle.The reason for this is that we call
:erlang.phash2
, passing it the "erlang native time" representation of the interval.:erlang.phash2
has a max input value of2^32
, and2^32
"erlang native time units" corresponds to4294
milliseconds.I'm aware that "native time units" can be OS dependent. I've tested this on my local development environment (macOS 12.6) and our staging environment (Alpine linux), and both return the same value for
i.e.
Suggested fix
When calling
:erlang.phash2
, we don't really need native time resolution, we could just convert to milliseconds when callingphash2
, then convert back to native time units.I can put in a PR for this.
Thanks!