From nobody Mon Feb 07 18:45:56 2022 X-Original-To: dev-commits-ports-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C9CEC19B1195; Mon, 7 Feb 2022 18:45:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jsw846K46z4qtg; Mon, 7 Feb 2022 18:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644259557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sQamZHGNzvFKGNLNnoDrOQTsG7e4GfbfavGxI6X/BP8=; b=jmztuvgSo5kr8jl3VQ8I6o8n7YE5Mi/GGOPte3SK2/6753sIkbcyfLHWNvp2Brf6wbwtCR AQoRty37SWbU3LMwsFu8rjrjq5OtOePLl+/anBbtNvalI+YjDAR3Cdk3+BuAqk6zzszJEN nWKWnkmD23v0H3ALM+Lt0ze3UANcqbyjhuMl65fnyGab1xYSh4pEgjeyNkhf8rDJuu79p6 +mllLpXXtaF+PhtM4QpDy94aXF5Dzm/gmEsXeaG9Y5taAk8KvAbadYO1cuhVBTGPcqUCpP wjZfN9RIguWC8epM6vN7fVqYF2hxYml9V+WvsjCvfvJ1q38oRz/PXf6tVztO1Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 65FA02934; Mon, 7 Feb 2022 18:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 217Ijuv4075232; Mon, 7 Feb 2022 18:45:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 217Ijucs075231; Mon, 7 Feb 2022 18:45:56 GMT (envelope-from git) Date: Mon, 7 Feb 2022 18:45:56 GMT Message-Id: <202202071845.217Ijucs075231@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Tobias Kortkamp Subject: git: 060529bfd15b - main - ports-mgmt/sccache-overlay: Use Unix sockets and fix Poudriere builds List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-main@freebsd.org X-BeenThere: dev-commits-ports-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tobik X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 060529bfd15bb104547b1c11f76171e3486e6b9c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644259557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=sQamZHGNzvFKGNLNnoDrOQTsG7e4GfbfavGxI6X/BP8=; b=mu4kWgQKL4Qcmq1Jp9VxouCIf4kszUgZqnROL33kBYNUMiuFd1RTLlsoXddhu3UGadHHHm w6OvL3739QTEyUPx9yMap9b4Nd5664cf2JbUQMIKvFkKLzn9XDcSuDzrxFcIpgzXWAkzaG 91xiuvBARImMd6zXInhJqe9X/BfZiknUtLfSO22n+6Mt6KpxmPXZB95PJtW3/wMy9XeWUQ PNJfAuE6i30vT+WPr/09VK/TzJ5Fb8meMAQxvhOvkRMDKExGhz3y8+x3rYeU9QKCkDtm9f wMxMI788dRJCfm4OfWxMqqOoqEbhxut+q1m8f+gLa5ksiLQXG48eARmwuz4lWA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644259557; a=rsa-sha256; cv=none; b=A56XTY/cGxfLT3aUQ5REnrJWTConq2+LWRNo42oqNxD8ihxGRidi1ThvTht/N83THMQD3w RjBVDVctoKuN/LvFwEVnf6dyND+0fdBqsCoZ+fBuwlqbkbhRovBV7Wa2d3wGy74KdaPHqu yqL59eBd3N5Do795cGGLTwo7o6lkX/lpL111HNpP8RX0DeoKlc9V6rRrMoWe0B+4Rdq/iJ O6GQ3fxAESczevia8cXug8U3pVysqOde3YaZcohwo335U6cOP31nDc+tHmTmUAv7eWtVsy Sui/iDVk9jYN8QLtRz1ORdscgI6JMhslM4NlpK47fNdaocZdsa8PQHiBhnww8w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by tobik: URL: https://cgit.FreeBSD.org/ports/commit/?id=060529bfd15bb104547b1c11f76171e3486e6b9c commit 060529bfd15bb104547b1c11f76171e3486e6b9c Author: Tobias Kortkamp AuthorDate: 2022-02-07 18:39:59 +0000 Commit: Tobias Kortkamp CommitDate: 2022-02-07 18:39:59 +0000 ports-mgmt/sccache-overlay: Use Unix sockets and fix Poudriere builds Poudriere builder jails seem to share one network namespace which is problematic when building packages in parallel since sccache binds to localhost:4226. This then leads to jails reusing the sccache instance from other jails which is problematic and can cause failures like 1/ missing files due to the filesystem separation: sccache: caused by: No such file or directory (os error 2) 2/ the sccache instance suddenly going away when a parallel build finishes and Poudriere shuts down the jail and kills all of its processes: sccache: error: failed to execute compile sccache: caused by: Failed to send data to or receive data from server sccache: caused by: Failed to read response header sccache: caused by: failed to fill whole buffer To properly namespace sccache instances we can use Unix sockets. There is a request [1] for adding support for Unix sockets upstream but no code has been written for that AFAICT. This commit hacks in support for them which should be just about ok for our purposes. [1] https://github.com/mozilla/sccache/issues/933 Tested by: jrm --- ports-mgmt/sccache-overlay/Makefile | 2 +- ports-mgmt/sccache-overlay/files/Mk/bsd.overlay.mk | 7 ++- .../sccache-overlay/files/patch-src_client.rs | 38 +++++++++++++ .../sccache-overlay/files/patch-src_server.rs | 66 ++++++++++++++++++++++ ports-mgmt/sccache-overlay/files/pkg-message.in | 7 +++ 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/ports-mgmt/sccache-overlay/Makefile b/ports-mgmt/sccache-overlay/Makefile index 3aa94da0d083..791f931c6de0 100644 --- a/ports-mgmt/sccache-overlay/Makefile +++ b/ports-mgmt/sccache-overlay/Makefile @@ -1,7 +1,7 @@ PORTNAME= sccache DISTVERSIONPREFIX= v DISTVERSION= 0.2.15 -PORTREVISION= 3 +PORTREVISION= 4 CATEGORIES= ports-mgmt PKGNAMESUFFIX= -overlay diff --git a/ports-mgmt/sccache-overlay/files/Mk/bsd.overlay.mk b/ports-mgmt/sccache-overlay/files/Mk/bsd.overlay.mk index da959aae4e3a..90f590b701fc 100644 --- a/ports-mgmt/sccache-overlay/files/Mk/bsd.overlay.mk +++ b/ports-mgmt/sccache-overlay/files/Mk/bsd.overlay.mk @@ -1,8 +1,8 @@ .if !defined(_SCCACHE_OVERLAY_INCLUDED) && !defined(NO_SCCACHE) _SCCACHE_OVERLAY_INCLUDED= yes -_SCCACHE_SIZE_DEFAULT= 16G -SCCACHE_SIZE?= ${_SCCACHE_SIZE_DEFAULT} +SCCACHE_SIZE?= 16G +SCCACHE_UNIX_LISTEN?= /tmp/sccache-overlay.socket _SCCACHE_LIBS= ${LOCALBASE}/share/sccache/overlay/lib .for odir in ${OVERLAYS} @@ -26,7 +26,8 @@ IGNORE= SCCACHE_DIR not set _SCCACHE_ENV= RUSTC_WRAPPER="${SCCACHE_BIN}" \ SCCACHE_CACHE_SIZE="${SCCACHE_SIZE}" \ SCCACHE_DIR="${SCCACHE_DIR}" \ - SCCACHE_MAX_FRAME_LENGTH=104857600 + SCCACHE_MAX_FRAME_LENGTH=104857600 \ + SCCACHE_UNIX_LISTEN="${SCCACHE_UNIX_LISTEN}" CONFIGURE_ENV+= ${_SCCACHE_ENV} MAKE_ENV+= ${_SCCACHE_ENV} diff --git a/ports-mgmt/sccache-overlay/files/patch-src_client.rs b/ports-mgmt/sccache-overlay/files/patch-src_client.rs new file mode 100644 index 000000000000..84ed56b0e4eb --- /dev/null +++ b/ports-mgmt/sccache-overlay/files/patch-src_client.rs @@ -0,0 +1,38 @@ +--- src/client.rs.orig 2021-01-12 22:25:51 UTC ++++ src/client.rs +@@ -17,20 +17,21 @@ use crate::protocol::{Request, Response}; + use crate::util; + use byteorder::{BigEndian, ByteOrder}; + use retry::{delay::Fixed, retry}; ++use std::env; + use std::io::{self, BufReader, BufWriter, Read}; +-use std::net::TcpStream; ++use std::os::unix::net::UnixStream; + + /// A connection to an sccache server. + pub struct ServerConnection { + /// A reader for the socket connected to the server. +- reader: BufReader, ++ reader: BufReader, + /// A writer for the socket connected to the server. +- writer: BufWriter, ++ writer: BufWriter, + } + + impl ServerConnection { + /// Create a new connection using `stream`. +- pub fn new(stream: TcpStream) -> io::Result { ++ pub fn new(stream: UnixStream) -> io::Result { + let writer = stream.try_clone()?; + Ok(ServerConnection { + reader: BufReader::new(stream), +@@ -65,7 +66,8 @@ impl ServerConnection { + /// Establish a TCP connection to an sccache server listening on `port`. + pub fn connect_to_server(port: u16) -> io::Result { + trace!("connect_to_server({})", port); +- let stream = TcpStream::connect(("127.0.0.1", port))?; ++ let unix_socket_path = env::var_os("SCCACHE_UNIX_LISTEN").unwrap(); ++ let stream = UnixStream::connect(unix_socket_path)?; + ServerConnection::new(stream) + } + diff --git a/ports-mgmt/sccache-overlay/files/patch-src_server.rs b/ports-mgmt/sccache-overlay/files/patch-src_server.rs new file mode 100644 index 000000000000..70e9f5fcd2a2 --- /dev/null +++ b/ports-mgmt/sccache-overlay/files/patch-src_server.rs @@ -0,0 +1,66 @@ +--- src/server.rs.orig 2021-01-12 22:25:51 UTC ++++ src/server.rs +@@ -63,6 +63,7 @@ use tokio_io::{AsyncRead, AsyncWrite}; + use tokio_serde_bincode::{ReadBincode, WriteBincode}; + use tokio_tcp::TcpListener; + use tokio_timer::{Delay, Timeout}; ++use tokio_uds::UnixListener; + use tower::Service; + + use crate::errors::*; +@@ -430,8 +431,9 @@ pub fn start_server(config: &Config, port: u16) -> Res + } + + pub struct SccacheServer { ++ unix_socket_path: String, + runtime: Runtime, +- listener: TcpListener, ++ listener: UnixListener, + rx: mpsc::Receiver, + timeout: Duration, + service: SccacheService, +@@ -447,8 +449,8 @@ impl SccacheServer { + dist_client: DistClientContainer, + storage: Arc, + ) -> Result> { +- let addr = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port); +- let listener = TcpListener::bind(&SocketAddr::V4(addr))?; ++ let unix_socket_path = env::var("SCCACHE_UNIX_LISTEN")?; ++ let listener = UnixListener::bind(&unix_socket_path)?; + + // Prepare the service which we'll use to service all incoming TCP + // connections. +@@ -457,6 +459,7 @@ impl SccacheServer { + let service = SccacheService::new(dist_client, storage, &client, pool, tx, info); + + Ok(SccacheServer { ++ unix_socket_path, + runtime, + listener, + rx, +@@ -493,7 +496,7 @@ impl SccacheServer { + /// Returns the port that this server is bound to + #[allow(dead_code)] + pub fn port(&self) -> u16 { +- self.listener.local_addr().unwrap().port() ++ 0 + } + + /// Runs this server to completion. +@@ -510,6 +513,7 @@ impl SccacheServer { + + fn _run<'a>(self, shutdown: Box + 'a>) -> io::Result<()> { + let SccacheServer { ++ unix_socket_path, + mut runtime, + listener, + rx, +@@ -593,6 +597,8 @@ impl SccacheServer { + io::Error::new(io::ErrorKind::Other, e) + } + })?; ++ ++ std::fs::remove_file(unix_socket_path); + + info!("ok, fully shutting down now"); + diff --git a/ports-mgmt/sccache-overlay/files/pkg-message.in b/ports-mgmt/sccache-overlay/files/pkg-message.in index 800247b91ec1..d84fccb4eceb 100644 --- a/ports-mgmt/sccache-overlay/files/pkg-message.in +++ b/ports-mgmt/sccache-overlay/files/pkg-message.in @@ -9,6 +9,13 @@ Add this to /etc/make.conf SCCACHE_DIR= ${HOME}/.sccache OVERLAYS+= %%DATADIR%%/overlay +During the build a sccache server is started, bound to +${SCCACHE_UNIX_LISTEN} (default /tmp/sccache-overlay.socket). It +automatically shuts down after 600 seconds if nothing is using +it. To cleanly shut it down earlier use + +$ make sccache-stop + Poudriere setup ===============