From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: rlf@skyhvelv.net (Rolf) Newsgroups: gmane.lisp.guile.bugs Subject: bug#43625: Calling write may close the program silently Date: Fri, 25 Sep 2020 21:50:35 +0200 Message-ID: <87tuvlfxf8.fsf@skyhvelv.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5976"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) To: 43625@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat Sep 26 03:28:23 2020 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLz0h-0001RM-5h for guile-bugs@m.gmane-mx.org; Sat, 26 Sep 2020 03:28:23 +0200 Original-Received: from localhost ([::1]:53824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLz0g-0006dY-53 for guile-bugs@m.gmane-mx.org; Fri, 25 Sep 2020 21:28:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLz0P-0006cc-08 for bug-guile@gnu.org; Fri, 25 Sep 2020 21:28:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33991) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLz0M-0004ZJ-8m for bug-guile@gnu.org; Fri, 25 Sep 2020 21:28:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kLz0M-0007Nd-5W for bug-guile@gnu.org; Fri, 25 Sep 2020 21:28:02 -0400 X-Loop: help-debbugs@gnu.org 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-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160108362928288 (code B ref -1); Sat, 26 Sep 2020 01:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Sep 2020 01:27:09 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 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-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 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9891 Archived-At: 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