golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.29k stars 17.47k forks source link

net/smtp: TestTLSClient failures with "connection reset by peer" on freebsd #19229

Open dr2chase opened 7 years ago

dr2chase commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.8+ (development)

What operating system and processor architecture are you using (go env)?

freebsd-amd64-gce101

What did you do?

Tried to run Trybots for an unrelated change: https://go-review.googlesource.com/c/37333/#message-ae31a67c5f6927959d8d507bc5ae951e01fbc4e7

Observed failure, followed instructions to check https://build.golang.org

In the first column for freebsd-x64 (the left-hand one), I clicked through some of the failures in that column, and noticed the repeated occurrence of

--- FAIL: TestTLSClient (0.00s)
    smtp_test.go:610: client error: close tcp 127.0.0.1:46828->127.0.0.1:46827: connection reset by peer
FAIL
FAIL    net/smtp    0.016s

which is also what besmirched my otherwise-clean TryBot run.

josharian commented 7 years ago

Happened again: https://storage.googleapis.com/go-build-log/82d5c3e9/freebsd-amd64-gce101_318ec227.log. Going to mail a CL disabling the test for now.

gopherbot commented 7 years ago

CL https://golang.org/cl/37653 mentions this issue.

neelance commented 6 years ago

This test is failing with my fake networking for js/wasm. It might be flaky on freebsd/amd64 for the same reason. Here is what I found:

  1. client sends SMTP "QUIT"
  2. server receives "QUIT", closes TLS connection and socket
  3. socket "close" propagates to client, also closes the socket at the client
  4. client wants to close TLS connection, which wants to send a TLS "close notify", but the socket got already closed
  5. the error bubbles up and smtp.SendMail returns it
gopherbot commented 6 years ago

Change https://golang.org/cl/120958 mentions this issue: net: re-implement built-in simulated network on JS and NaCl

bcmills commented 5 years ago

Another failure, this time on freebsd-386-11_2: https://build.golang.org/log/f96ab0392ed0c683f8649fbb3686e9d74e3b30bb

--- FAIL: TestTLSClient (0.01s)
    smtp_test.go:746: client error: close tcp 127.0.0.1:46749->127.0.0.1:46748: connection reset by peer
FAIL
FAIL    net/smtp    0.049s
bcmills commented 3 years ago

2020-12-04T18:03:43-edf60be/freebsd-386-11_2 2020-11-07T14:23:20-bb9a96d/freebsd-arm64-dmgk 2020-04-25T02:19:12-49f10f3/freebsd-arm-paulzhol 2019-11-07T08:25:32-7a2baa9/freebsd-386-12_0 2019-10-31T17:09:50-7de15e3/freebsd-arm-paulzhol 2019-09-09T22:56:39-5e907e3/freebsd-arm-paulzhol

bcmills commented 3 years ago

2021-02-19T00:40:16-985d087/freebsd-386-11_2 2021-02-18T17:57:50-a5c8a15/freebsd-386-11_2 2020-12-23T17:01:35-49d0b23/freebsd-386-11_2 2020-12-11T22:13:50-41d8e61/freebsd-386-11_2 2020-12-10T23:24:38-e012d0d/freebsd-arm64-dmgk 2020-12-09T16:38:26-db6032d/freebsd-arm64-dmgk

bcmills commented 2 years ago

greplogs --dashboard -md -l -e '(?m)FAIL: TestTLSClient.*\n.*connection reset by peer' --since=2021-02-20

2021-11-17T04:55:12-1d004fa/freebsd-386-11_4 2021-11-05T17:23:06-37951d8/freebsd-386-12_2 2021-11-02T13:43:24-4d7bf41/freebsd-386-11_4 2021-10-27T21:34:20-4fefd43/freebsd-386-11_4 2021-10-21T15:42:41-8b0bea9/freebsd-386-11_4 2021-10-20T20:39:29-1dff8f0/freebsd-386-11_4 2021-09-21T23:11:47-30faf96/freebsd-arm64-dmgk 2021-06-04T14:31:24-c6b6211/freebsd-386-11_4 2021-06-04T01:26:43-b29b123/freebsd-386-12_2 2021-05-04T23:35:34-137be77/freebsd-386-11_4 2021-05-03T19:14:16-9f34703/freebsd-386-11_4 2021-04-28T20:36:50-fa6ed6e/freebsd-386-11_4 2021-04-23T14:06:54-d4bfe00/freebsd-386-11_2 2021-04-22T18:17:00-b6ff3c6/freebsd-386-11_4 2021-04-18T17:40:12-4efd581/freebsd-386-11_2 2021-04-08T19:30:34-ecca94a/freebsd-386-11_2 2021-04-06T23:39:42-972e883/freebsd-386-12_0 2021-03-25T21:30:55-11b4aee/freebsd-arm64-dmgk 2021-03-24T21:19:57-63e9f6d/freebsd-386-11_2 2021-03-23T23:08:19-769d4b6/freebsd-386-11_2 2021-03-23T22:17:52-dc289d3/freebsd-arm64-dmgk 2021-03-04T03:29:58-95ff296/freebsd-386-12_0 2021-02-20T03:54:50-d4b2638/freebsd-386-11_2

gopherbot commented 2 years ago

Change https://golang.org/cl/370137 mentions this issue: net/smtp: skip TestTLSSClient on all freebsd platforms

bcmills commented 2 years ago

A proper fix for this will likely need someone with at least some expertise in the TLS protocol and/or the FreeBSD network stack (i.e. not me 😅).

FiloSottile commented 3 weeks ago

I don't think the issue is crypto/tls trying to send the close notify alert, or we would see tls: failed to send closeNotify alert in the error. Instead, the error is returned by the actual net.Conn.Close, which suggests a difference in behavior when trying to close already-closed connections in FreeBSD.