daml/nix
Andreas Herrmann a1da025b78
FreePort draw from outside ephemeral port range (#10774)
* Test case for LockedFreePort not colliding with port 0

changelog_begin
changelog_end

* Discover dynamic port range on Linux

* Random port generator outside ephemeral range

* remove dev comments

* Draw FreePort from outside the ephemeral port range

Note, there is a race condition between the socket being closed and the
lock-file being created in LockedFreePort. This is not a new issue, it
was already present with the previous port 0 based implementation.

LockedFreePort handles this by attempting to find a free port and taking
a file lock multiple times.

But, it could happen that A `find`s port N, and obtains the lock, but
doesn't bind port N again, yet; then B binds port N during `find`; then
A attempts to bind port N before B could release it again and fails
because B still holds it.

* Select dynamic port range based on OS

* Detect dynamic port range on MacOS and Windows

* Import sysctl from Nix on MacOS

changelog_begin
changelog_end

* Windows line separator

* FreePort helpers visibility

* Use more informative exception types

* Use a more light weight unit test

* Add comments

* Fix Windows

* Update libs-scala/ports/src/main/scala/com/digitalasset/ports/FreePort.scala

Co-authored-by: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>

* Update libs-scala/ports/src/main/scala/com/digitalasset/ports/FreePort.scala

Co-authored-by: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>

* Add a comment to clarify the generated port range

* fmt

* unused import

* Split libs-scala/ports

Splits the FreePort and LockedFreePort components into a separate
library as this is only used for testing purposes.

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
Co-authored-by: Stefano Baghino <43749967+stefanobaghino-da@users.noreply.github.com>
2021-09-07 15:41:43 +02:00
..
certs Remove custom truststore remains (#280) 2019-04-08 11:19:44 +02:00
nixpkgs Upgrade Nixpkgs [KVL-1045] (#10624) 2021-08-20 12:34:19 +00:00
overrides Upgrade nixpkgs (#8190) 2021-02-08 11:12:07 +00:00
tools Remove trace_context field from Ledger API [KVL-1021] (#10256) 2021-07-15 19:06:25 +02:00
bazel-cc-toolchain.nix Hermetic nixpkgs_cc_toolchain (#5976) 2020-05-18 18:03:51 +02:00
bazel-cc-wrapper-response-file.patch Upgrade to Bazel 4.0 (#8798) 2021-02-11 10:08:47 +01:00
bazel-retry-cache.patch Retry bazel cache up & downloads (#10156) 2021-07-01 14:40:29 +02:00
bazel.nix FreePort draw from outside ephemeral port range (#10774) 2021-09-07 15:41:43 +02:00
BUILD.bazel update copyright notices for 2021 (#8257) 2021-01-01 19:49:51 +01:00
default.nix [JSON-API] vanilla oracle_perf ci job (#10688) 2021-09-02 09:31:56 +01:00
nixpkgs.nix Upgrade to Scala 2.12.14 and 2.13.6. (#10573) 2021-08-12 14:25:53 +00:00