Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWGLJ-0002Iy-Rb for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2020 10:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kWGLI-0007Es-Q1 for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2020 10:00:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kWGLI-0007El-HS for pgsql-bugs@lists.postgresql.org; Sat, 24 Oct 2020 10:00:08 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kWGLF-0008QX-Gu for pgsql-bugs@lists.postgresql.org; Sat, 24 Oct 2020 10:00:08 +0000 Received: by mail-lf1-x142.google.com with SMTP id j30so5176570lfp.4 for ; Sat, 24 Oct 2020 03:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=HHe4nNRBT2aVP7kfV34pfxKjZh/RqY8Wjg6Ab7vNOv0=; b=EXz2MWH5Nw8ORP+Da+qcDln/9bE1gjGVsz0+Vcg47P7tU6ljRYJnFcyICWhH4egN0p LL6hxvJIrpun5h+aaFaif3extgbnCpFr1mZnOULkUvG35ywVSuzc6N0BSedUAnSC6NRw Y80/gTvUd4Hr0VKb4A5ZrUdduVpKqOac4ITYdt2N5UJUna0EXiXawA9o4qbClssWPYwO pdVibn8AlNoLQDRjxCu7urXaW9Cm7BODTA0SPUWO/Wa1ArvXHQFNevEqQTrgY9eWdaLm sXVeHysUn4x0KsvVP4cpjPwxFHKmMzjKvnSK8zjWDd6I8LkcLleT4ylsz3EqS4h5eiWM p/gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=HHe4nNRBT2aVP7kfV34pfxKjZh/RqY8Wjg6Ab7vNOv0=; b=WC7P7GNTJSsgQdPnRfejeqeIfZfhIWkFM5970LE1rRGEQLQhsRUBaKM3zwTnnEqjV8 5bQPi+nxYZ1F7W6PWVHahJfDePXUMoqIEbQmVpf8qlGpdx7kXh34dGqep2nZZs9d6LwJ IyyoXdFhAdEu+2zHAHcwLCBw3cRgnBvYxbD2q18ekXlzbHQYOwMzTac5mGvWN1bFSYiA HE4wQY2CMfB4WC1OU5fQEMjB+V6Ac0C02lSNgVDHHdfZltnN2l48FlCKnpYcR2Ix/hl/ E2KAObq7IW8bLNnmUzKhVCzHpsFL4dVGHU/eHD6PXkReeqpqPADIg4zlXKVVt7toaodC L6lA== X-Gm-Message-State: AOAM532PR/HHNKzzOeduq0LHCWlghvuRbWawlHBXDY6vOBGvNaO1nTBc WzDWVt2cTmaXzdxTCDtp4XgSgNM18wM= X-Google-Smtp-Source: ABdhPJzSYxIkPipaJZ5QLq2dIlLlFE2eZtpAlhOm03+xdoSkNd5mkW9EsuhjpQiB05hONUR6FmzJyQ== X-Received: by 2002:ac2:424b:: with SMTP id m11mr2316964lfl.339.1603533602603; Sat, 24 Oct 2020 03:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.6.144]) by smtp.gmail.com with ESMTPSA id b15sm466688ljp.117.2020.10.24.03.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 Oct 2020 03:00:02 -0700 (PDT) Subject: Re: BUG #16678: The ecpg connect/test5 test sometimes fails on Windows To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org References: <16678-253e48d34dc0c376@postgresql.org> <434311.1603135136@sss.pgh.pa.us> From: Alexander Lakhin Message-ID: Date: Sat, 24 Oct 2020 13:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <434311.1603135136@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 19.10.2020 22:18, Tom Lane wrote: > Yeah, we've come to that conclusion before, see for instance > https://www.postgresql.org/message-id/flat/E1iaD8h-0004us-K9%40gemulon.postgresql.org > > I haven't heard any non-unpleasant ideas for working around it. > > One thought that might or might not improve matters is for > the backend to explicitly close() the socket before exiting. > We intentionally don't do that (cf 268313a95), but maybe > doing it on Windows would be better than the existing issue > --- assuming it fixes the issue, that is. Yes, close() fixes the issue for me, but I'm afraid that it maybe not 100% reliable (and Amit Kapila in [1] talked about it in the aforementioned discussion). Microsoft suggests using shutdown() to assure that all data is sent. https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown And the same is said in not so new, but may be still relevant article: https://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable So I've also tested on Windows the following version:         secure_close(MyProcPort);         shutdown(MyProcPort->sock, SD_SEND);         for(;;) {             char buffer[1000];             int res = recv(MyProcPort->sock, buffer, 1000, 0);             if (res <= 0)                 break;         }         closesocket(MyProcPort->sock); And it works too. On my Ubuntu localhost I can't reproduce losing a message (up to 1MB) on FATAL exit, so probably in 2020 such a socket cherishing is needed only for Windows. But I allow that with with some other systems and/or a real network the data sent just before exit can be lost. Best regards, Alexander