From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS24940 94.130.0.0/16 X-Spam-Status: No, score=-3.0 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (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) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 5D5291F601 for ; Wed, 7 Dec 2022 07:57:13 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.b="MnpGFeWq"; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 6A48F7E5DA; Wed, 7 Dec 2022 07:57:03 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=MnpGFeWq; dkim-atps=neutral Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 165F57E571 for ; Wed, 7 Dec 2022 07:56:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=q4xJ3kQ9TxA+l3rNGFV2+1l466/sHiKbMsIFBti1Ptg=; b=MnpGFeWqxSwwnr0wYOtAx2MAY//5L1SFT6phPKKReU0XDZwOc9RBpNU/nAtPTmWkFuBj aa5SQLsf7nezXrPUoangY8B+i6o+PAfjFq5OX8M2kgz3JBZ8C1bQFPzXsyBwDKCHMrY57F GU5zeHUqvkYfRb3zJuJOdGa8/4WaqPaiFVMnfHPkEqxiU8Y5GzHr9gWn8hWEjrKi18rCP9 J/fGWi6B9sgjvAlt35VRyuw04pqisdU7I5GWf+h2MNTnZKHolhelDM6436Bwlz8iqQ8Zes k6t693Qed2ZlU0/KfyqeB3DfzR7YQljlMVFiQ72rTZl4Fa+M45isZICkkEZyho4Q== Received: by filterdrecv-8569859b9-xv7fj with SMTP id filterdrecv-8569859b9-xv7fj-1-6390474A-15 2022-12-07 07:56:58.559026168 +0000 UTC m=+1673408.937986030 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-4 (SG) with ESMTP id VoewRD62SnmRJ7uL0diqKw for ; Wed, 07 Dec 2022 07:56:58.516 +0000 (UTC) Date: Wed, 07 Dec 2022 07:56:58 +0000 (UTC) From: "byroot (Jean Boussier)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 19012 X-Redmine-Issue-Author: byroot X-Redmine-Sender: byroot X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 87582 X-SG-EID: =?us-ascii?Q?Dq8GNIcVqP8cs5uR+EIAabfg3LE9XdC6dZ5KYNrMpf6VzBWG6HqArcu5raQjXL?= =?us-ascii?Q?IGTFdxKHUt7++67+KD54pNYXheirMcsUIf3sdgF?= =?us-ascii?Q?Riq06jm9kL2+Kyxxw7GgFsWcwfvcfmbOdk597nB?= =?us-ascii?Q?xmfb7ZWvIJ7CgBB9ZH3i9fy6nmFhEYAnCn5Xv=2Fy?= =?us-ascii?Q?lJ=2FFOxX6NgOK607dTSKA+DPaKtlwnGNFv=2FJW7Q5?= =?us-ascii?Q?w+asqDjBm2CmXpnYKGcIhzWwr=2FKQ5EOtGheX4lZ?= =?us-ascii?Q?sqAFonKGDiAOyP7+5f8PQ=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: W7WJNRA66NGFMWWNEE4HQC3GLURJENI6 X-Message-ID-Hash: W7WJNRA66NGFMWWNEE4HQC3GLURJENI6 X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:111227] [Ruby master Bug#19012] BasicSocket#recv* methods return an empty packet instead of nil on closed connections List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #19012 has been updated by byroot (Jean Boussier). I was able to implement the desired behavior in https://github.com/ruby/ruby/pull/6407 ---------------------------------------- Bug #19012: BasicSocket#recv* methods return an empty packet instead of nil on closed connections https://bugs.ruby-lang.org/issues/19012#change-100516 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `man recvmsg(2)` states: > Return Value > These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutdown. But somehow the entire `receiv` family of methods in Ruby seem to interpret `0` as empty string instead of "EOF". ```ruby require 'socket' puts "=== pipes ===" r, w = IO.pipe r.read_nonblock(1, exception: false) # => :wait_readable w.close r.read_nonblock(1, exception: false) # => nil (EOF) puts "=== sockets ====" r, w = UNIXSocket.socketpair r.read_nonblock(1, exception: false) # => :wait_readable r.recvmsg_nonblock(1, exception: false) # => :wait_readable r.recv_nonblock(1, exception: false) # => :wait_readable w.close r.read_nonblock(1, exception: false) # => nil (EOF) r.recvmsg_nonblock(1, exception: false) # => ["", #, 128]] r.recvmsg # => ["", #, 0]] r.recv_nonblock(1, exception: false) # => "" ``` ### Expected behavior I would expect `recvmsg_nonblock`, `recvmsg`, `recv_nonblock` and `recv` to return `nil` when the connection is closed. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/