From patchwork Sun Feb 10 14:28:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1039426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495735-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gdcproject.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="AD4NxhlV"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43yBBX2Qjcz9s4Z for ; Mon, 11 Feb 2019 01:29:19 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=WNFoqZ3MBNDruU8AbaEwOSlCorS9gJ/XcQxyxXyO3tf8Dq hlJkRyy7dGmRVzprDnH7kMWAUyltNyLw73XNYX+fj9a3NFwRIF2SRPXSwZPD4DLJ HSlGlyUl4P9XxmfQ4C5EFuaNrxpwt/8KHqk09VbpbJKRnCVPK0ALEMnLj4gQk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=YaEqYYrgS26JELAYkkmQmS1OrjQ=; b=AD4NxhlVbbmc8QtE9qtu xi/dhzOIB5Ha5oa86iKUMSPlVIoGrO/Aif/rhhFnG2zcxGFumHdKrMvHlCyf7PYx EwpTgcpKkhHe1yy9Ie8TvrDgV5zJFNgKPXYIEJHdcq91BHCQvJGrdYSnTueqQSll HfKlifVsaPHfozp7Us3RoMk= Received: (qmail 65835 invoked by alias); 10 Feb 2019 14:29:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 65825 invoked by uid 89); 10 Feb 2019 14:29:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Request, H*r:sk:mail-qt, Hx-spam-relays-external:sk:mail-qt, H*RU:sk:mail-qt X-HELO: mail-qt1-f176.google.com Received: from mail-qt1-f176.google.com (HELO mail-qt1-f176.google.com) (209.85.160.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Feb 2019 14:29:09 +0000 Received: by mail-qt1-f176.google.com with SMTP id y20so9273328qtm.13 for ; Sun, 10 Feb 2019 06:29:09 -0800 (PST) MIME-Version: 1.0 From: Iain Buclaw Date: Sun, 10 Feb 2019 15:28:56 +0100 Message-ID: Subject: [PATCH PR d/88654] Committed phobos fix for thread deadlock in std.net.curl To: gcc-patches X-IsSubscribed: yes Hi, This patch is the library fix for a thread deadlock that occurred when libcurl is missing. It is only one half of the fix for the PR, the other is for the testsuite scripts to check that libcurl exists before attempting to run the std.net.curl unittest. Bootstrapped and tested on x86_64-linux-gnu (-m32) to verify test goes from timed out to just fail. Committed to trunk as r268746. diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index eee413903c0..aef240e0722 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -d4933a90b1e8446c04d64cd044658f2b33250bd3 +6c9fb28b0f8813d41798202a9d19c6b37ba5da5f The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/std/net/curl.d b/libphobos/src/std/net/curl.d index 9d751411705..e3ce527c303 100644 --- a/libphobos/src/std/net/curl.d +++ b/libphobos/src/std/net/curl.d @@ -178,7 +178,7 @@ version (unittest) import std.range; import std.stdio; - import std.socket : Address, INADDR_LOOPBACK, Socket, TcpSocket; + import std.socket : Address, INADDR_LOOPBACK, Socket, SocketShutdown, TcpSocket; private struct TestServer { @@ -192,6 +192,7 @@ version (unittest) private: string _addr; Tid tid; + TcpSocket sock; static void loop(shared TcpSocket listener) { @@ -215,20 +216,34 @@ version (unittest) private TestServer startServer() { + tlsInit = true; auto sock = new TcpSocket; sock.bind(new InternetAddress(INADDR_LOOPBACK, InternetAddress.PORT_ANY)); sock.listen(1); auto addr = sock.localAddress.toString(); auto tid = spawn(&TestServer.loop, cast(shared) sock); - return TestServer(addr, tid); + return TestServer(addr, tid, sock); } + __gshared TestServer server; + bool tlsInit; + private ref TestServer testServer() { - __gshared TestServer server; return initOnce!server(startServer()); } + static ~this() + { + // terminate server from a thread local dtor of the thread that started it, + // because thread_joinall is called before shared module dtors + if (tlsInit && server.sock) + { + server.sock.shutdown(SocketShutdown.RECEIVE); + server.sock.close(); + } + } + private struct Request(T) { string hdrs; @@ -429,7 +444,11 @@ if (isCurlConn!Conn) s.send(httpOK("Hello world")); }); auto fn = std.file.deleteme; - scope (exit) std.file.remove(fn); + scope (exit) + { + if (std.file.exists(fn)) + std.file.remove(fn); + } download(host, fn); assert(std.file.readText(fn) == "Hello world"); } @@ -491,7 +510,11 @@ if (isCurlConn!Conn) foreach (host; [testServer.addr, "http://"~testServer.addr]) { auto fn = std.file.deleteme; - scope (exit) std.file.remove(fn); + scope (exit) + { + if (std.file.exists(fn)) + std.file.remove(fn); + } std.file.write(fn, "upload data\n"); testServer.handle((s) { auto req = s.recvReq;