daml/runtime-components/non-repudiation-api/BUILD.bazel
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

63 lines
1.9 KiB
Python

# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load(
"//bazel_tools:scala.bzl",
"da_scala_library",
"da_scala_test",
)
da_scala_library(
name = "non-repudiation-api",
srcs = glob(["src/main/scala/**/*.scala"]),
scala_deps = [
"@maven//:com_typesafe_akka_akka_actor",
"@maven//:com_typesafe_akka_akka_http",
"@maven//:com_typesafe_akka_akka_http_core",
"@maven//:com_typesafe_akka_akka_http_spray_json",
"@maven//:com_typesafe_akka_akka_stream",
"@maven//:io_spray_spray_json",
"@maven//:org_scala_lang_modules_scala_collection_compat",
],
visibility = [
"//:__subpackages__",
],
deps = [
"//libs-scala/resources",
"//runtime-components/non-repudiation",
"@maven//:com_google_guava_guava",
"@maven//:org_slf4j_slf4j_api",
],
)
da_scala_test(
name = "test",
srcs = glob(["src/test/scala/**/*.scala"]),
resources = [
"src/test/resources/logback-test.xml",
],
scala_deps = [
"@maven//:com_typesafe_akka_akka_actor",
"@maven//:com_typesafe_akka_akka_http",
"@maven//:com_typesafe_akka_akka_http_core",
"@maven//:com_typesafe_akka_akka_http_spray_json",
"@maven//:com_typesafe_akka_akka_stream",
"@maven//:io_spray_spray_json",
"@maven//:org_scala_lang_modules_scala_collection_compat",
],
runtime_deps = [
"@maven//:ch_qos_logback_logback_classic",
],
deps = [
":non-repudiation-api",
"//ledger-api/grpc-definitions:ledger_api_proto_scala",
"//libs-scala/ports",
"//libs-scala/ports:ports-testing",
"//libs-scala/resources",
"//runtime-components/non-repudiation",
"//runtime-components/non-repudiation-testing",
"@maven//:com_google_guava_guava",
"@maven//:org_slf4j_slf4j_api",
],
)