`disconnect_all` does not work correctly with intervals above 4294
whilefalse opened this issue · comments
Please see https://github.com/whilefalse/disconnect_all for full reproduction information and more details.
Brief overview
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
System.convert_time_unit(floor(:math.pow(2, 32)), :native, :millisecond)
i.e.
4294
Suggested fix
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.
I can put in a PR for this.
Thanks!
Nice find! A PR is welcome!