X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6870387084A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1587482069; bh=Wo/NBDT9yNz30A3thGNFmF1MavAP8geZj0wtV2f0HWo=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=B4Vce6gnAst/Kja53HYvj5Qethn0cUxHzcYWQ6UBzWaWlCfUfPTOdVoL0jYppIRWo UOa/BOWvezbFFf85aZ/KR1wBWLeFz68e0IiWdaLRX0FpP6YLkdne4gPgVgAU0FwRwp y3YCgFghJfYVwwpCb5gR6kWehK65VLAxhLI4Biu4= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7E069386F02B X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=wlUpLOrlvxN6dOLdlOBTKTzT1261VeGllTBt/mIRAt4=; b=A5fKbUmUQ0Q0QlpeZmADVqAvrfomPn+0qI74kBUJKPtU4h32mtQJLoenFM8x/CvTps s9XJ9W60D4b60emq/Ho9msBHiOq+jqHFQbdgxaTxlZv/EWS0PHm/H++5LCYdpiWvSU8x BQs+ZyqVaA6y+p1ZGzR2Pt8LCPdxE1r3jpgP8wh40MT7Nqf5Gs2hj6As8bP6e6gyHcdV G2NqNXZoWpo2PpRShKfStadNA7BfaN8/A3iP4Qwjq6BGLBUGaoJeZZC6k71Qe8bAEYHn nxbGOmYZpKUgemSpH6whtB/MBCKQJx/10Er2zM5XtHo7fY3/GYowwSXRZULsCC5Vo4qt 7T/g== X-Gm-Message-State: AGi0Pua17Nsd9JZ2+CVxF4QsC7MTvEuUQlcXt3s3dfh/EWbaQe5AFfrc m3AoV02NH5BpZNWGiWfJhERHmrmBHmU1j7MtY8+PvBw9 X-Google-Smtp-Source: APiQypJBXB/S3gujS9er4zkj6ME92vb7nkKJcV1RiMxRpTNcZtX0ZMUkqR2zCBBQdrUSCA6OAVeu9ViZLF2VqT0mxWk= X-Received: by 2002:a2e:a549:: with SMTP id e9mr13633366ljn.28.1587482063870; Tue, 21 Apr 2020 08:14:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 21 Apr 2020 11:14:10 -0400 Message-ID: Subject: Re: nc fails to connect the first time and then succeeds To: cygwin AT cygwin DOT com X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.29 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Jack Adrian Zappa via Cygwin Reply-To: Jack Adrian Zappa Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Cygwin" Nm. I figured it out. Seems if you don't specify what type of listener, it'll default to IP4. When you create a sender, it'll try first using IP6 and then fall back to IP4. It's that first connection that is causing the failure. If you specify the listener to use IP6, then it works fine. Thanks, A On Tue, Apr 21, 2020 at 3:48 AM Jack Adrian Zappa wrote: > > I was trying to do some testing of a ssh port forwarding issue I was > having, by trying to reduce the problem into something simpler. So I > reached for netcat (nc). Turns out that when trying to connect a > listener to a sender directly, it will fail first and then succeed. > > Example: > In terminal 1 we do: > > $ nc -l 1234 > > nc waits. In terminal 2 we do: > > $ nc -v localhost 1234 > nc: connect to localhost port 1234 (tcp) failed: Connection refused > Connection to localhost 1234 port [tcp/*] succeeded! > > The initial failure is fine when connecting directly, but this failure > is disastrous when connecting through an ssh connection. This is > because when the sshd connects to the nc listener, it will first fail > and then succeed. However, that first failure makes the sshd think > that there is no connection to be had and just closes the tunnel, > making the nc sender just terminate. > > Is this a coding error or somehow by design? If by design, then why? > If by error, then when can we expect this to be fixed? > > Thanks, > > > Adrian -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple