From unknown Sat Jun 14 00:07:58 2025 X-Loop: help-debbugs@gnu.org Subject: bug#43625: Calling write may close the program silently Resent-From: rlf@skyhvelv.net (Rolf) Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 26 Sep 2020 01:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 43625 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 43625@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.160108362928288 (code B ref -1); Sat, 26 Sep 2020 01:28:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 Sep 2020 01:27:09 +0000 Received: from localhost ([127.0.0.1]:45534 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kLyzT-0007M9-Th for submit@debbugs.gnu.org; Fri, 25 Sep 2020 21:27:09 -0400 Received: from lists.gnu.org ([209.51.188.17]:44368) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kLtke-00087w-Uk for submit@debbugs.gnu.org; Fri, 25 Sep 2020 15:51:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLtke-0001Kc-Ld for bug-guile@gnu.org; Fri, 25 Sep 2020 15:51:28 -0400 Received: from smtp.domeneshop.no ([2a01:5b40:0:3005::1]:50786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLtkc-00089K-K0 for bug-guile@gnu.org; Fri, 25 Sep 2020 15:51:28 -0400 Received: from 78-26-58-206.network.trollfjord.no ([78.26.58.206]:49026 helo=nasu) by smtp.domeneshop.no with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLtkW-0004WD-8x for bug-guile@gnu.org; Fri, 25 Sep 2020 21:51:20 +0200 From: rlf@skyhvelv.net (Rolf) Date: Fri, 25 Sep 2020 21:50:35 +0200 Message-ID: <87tuvlfxf8.fsf@skyhvelv.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a01:5b40:0:3005::1; envelope-from=rlf@skyhvelv.net; helo=smtp.domeneshop.no X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Mailman-Approved-At: Fri, 25 Sep 2020 21:27:06 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Greetings, I am experiencing some difficulties writing a TCP server in Guile. It is a simple server where every connection gets its own thread. I have discovered that if a client force closes the connection for any reason (the client program crashing, for instance), the server program will silently exit with a status code 141, without rasing any exceptions, if it attempts to write to the port of that connection. Below is some sample code: (define listening-socket (socket PF_INET SOCK_STREAM 0)) (setsockopt listening-socket SOL_SOCKET SO_REUSEADDR 1) (bind listening-socket AF_INET (inet-pton AF_INET "127.0.0.1") 60000) (listen listening-socket 1) (define accepted (car (accept listening-socket))) (sleep 5) ;; make some time for the client to force close ;(close accepted) ;; if a graceful close happens before the write, a ;; wrong type argument error is raised, as expected (write "I will never arrive" accepted) ;; program exits w/ 141 here ;; when the client forces the ;; connection closed (display "Unreachable call") (newline) Given that the example code is saved to the file "test-write-fail.scm", it may be reproduced by running guile test-write-fail.scm; echo "Exit code: $?" and connecting to it using netcat (nc 127.0.0.1 60000), then immediately closing the connection by doing a CTRL+C and waiting 5 seconds. The server will terminate without displaying "Unreachable call" and you should see an exit code of 141. In such an event, port-closed? will also return #f, so checking it does not seem to be of any use. I have tested the same using read, but it does nothing instead of exiting prematurely: (define listening-socket (socket PF_INET SOCK_STREAM 0)) (setsockopt listening-socket SOL_SOCKET SO_REUSEADDR 1) (bind listening-socket AF_INET (inet-pton AF_INET "127.0.0.1") 60000) (listen listening-socket 1) (define accepted (car (accept listening-socket))) (sleep 5) (read accepted) ;; does nothing, exits with 0 (display "You should see this") (newline) I have produced the same results using Guile 3.0.2 and 2.2.6 on Linux, as well as 2.2.6 on OpenBSD, all x86_64 builds. Regards, Rolf