daml/libs-scala/ports/BUILD.bazel

54 lines
1.3 KiB
Python
Raw Normal View History

# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
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 16:41:43 +03:00
load("@os_info//:os_info.bzl", "is_darwin")
load(
"//bazel_tools:scala.bzl",
"da_scala_library",
"da_scala_test",
)
da_scala_library(
name = "ports",
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 16:41:43 +03:00
srcs = [
"src/main/scala/com/digitalasset/ports/Port.scala",
"src/main/scala/com/digitalasset/ports/PortFiles.scala",
"src/main/scala/com/digitalasset/ports/PortLock.scala",
],
scala_deps = [
"@maven//:org_scalaz_scalaz_core",
],
tags = ["maven_coordinates=com.daml:ports:__VERSION__"],
visibility = [
"//visibility:public",
],
)
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 16:41:43 +03:00
da_scala_library(
name = "ports-testing",
srcs = [
"src/main/scala/com/digitalasset/ports/FreePort.scala",
"src/main/scala/com/digitalasset/ports/LockedFreePort.scala",
],
data = ["@sysctl_nix//:bin/sysctl"] if is_darwin else [],
visibility = [
"//visibility:public",
],
deps = [
":ports",
"//bazel_tools/runfiles:scala_runfiles",
],
)
da_scala_test(
name = "ports-tests",
srcs = glob(["src/test/suite/scala/**/*.scala"]),
scala_deps = [
"@maven//:org_scalaz_scalaz_core",
],
deps = [
":ports",
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 16:41:43 +03:00
":ports-testing",
],
)