Stops responding on port 80/443, setsockopt error

1. My Caddy version (caddy -version):

1.0.4

2. How I run Caddy:

/Library/LaunchDaemons/caddy.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Disabled</key>
  <false/>
  <key>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>caddy</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/bin/caddy</string>
    <string>-conf</string>
    <string>/usr/local/server/config/conf/Caddyfile</string>
    <string>-log</string>
    <string>/usr/local/var/log/caddy/caddy.log</string>
    <string>-email</string>
    <string>xxx@xxx.xxx</string>
    <string>-agree</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>SoftResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>8192</integer>
  </dict>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/caddy/stderr.txt</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/caddy/stdout.txt</string>
<key>WorkingDirectory</key>
<string>/usr/local/server</string>

a. System environment:

macOS 10.14 (18A391)

d. My complete Caddyfile:

xxx.com, www.xxx.com {
  root /usr/local/server/web/Public

  log / /usr/local/var/log/web/access.log "{combined}"
  errors /usr/local/var/log/web/error.log

  limits {
    header 1mb
    body 10mb
  }

  gzip {
    level 5
    min_length 1500
  }

  proxy / 127.0.0.1:8080 {
    except /images/ /pictures/ /scripts/ /styles/ /.well-known/ /ads.txt /app-ads.txt /apple-touch-icon /favicon.ico /robots.txt
  }
}

3. The problem I’m having:

I’ve been using Caddy on a Mac Mini for a few years now and it’s been perfectly stable. The site uses Caddy’s automated Let’s Encrypt support to serve over https, and requests on port 80 are automatically redirected to 443.

Over the last few months, I’ve been seeing a problem where the server stops responding on either port 80 or 443. The only fix is to restart Caddy. The one consistent thing I see in the logs before it stops working is a “setsockopt: invalid argument” entry like this:

2020/01/15 19:15:20 set tcp [::d8a8:8252]:443->75.104.86.94:7775: setsockopt: invalid argument

The only time I see this log entry is before the server stops responding on the port.

4. Error messages and/or full log output:

Example setsockopt message in context:

2020/01/15 18:50:22 [ERROR] failed to copy buffer:  readfrom tcp 127.0.0.1:61914->127.0.0.1:8080: read tcp 216.168.130.82:443->108.6.209.127:53275: use of closed network connection
2020/01/15 18:53:37 http: TLS handshake error from 18.206.119.3:60806: no certificate available for ''
2020/01/15 18:53:38 http: TLS handshake error from 34.227.163.139:44342: no certificate available for ''
2020/01/15 18:53:38 http: TLS handshake error from 54.242.196.201:36854: no certificate available for ''
2020/01/15 18:53:38 http: TLS handshake error from 54.172.112.30:51960: no certificate available for ''
2020/01/15 19:03:57 [ERROR] failed to copy buffer:  readfrom tcp 127.0.0.1:61947->127.0.0.1:8080: read tcp 216.168.130.82:443->108.6.209.127:53310: use of closed network connection
2020/01/15 19:12:34 [ERROR] failed to copy buffer:  readfrom tcp 127.0.0.1:61981->127.0.0.1:8080: read tcp 216.168.130.82:443->108.6.209.127:53339: use of closed network connection
2020/01/15 19:15:20 set tcp [::d8a8:8252]:443->75.104.86.94:7775: setsockopt: invalid argument
2020/01/15 19:16:06 [ERROR] failed to copy buffer:  read tcp 127.0.0.1:62001->127.0.0.1:8080: read: connection reset by peer
2020/01/15 19:16:06 [ERROR] failed to copy buffer:  readfrom tcp 127.0.0.1:62001->127.0.0.1:8080: read tcp 216.168.130.82:443->108.6.209.127:53353: use of closed network connection
2020/01/15 19:21:09 [INFO][cache:0xc0001d62d0] Scanning for stale OCSP staples
2020/01/15 19:21:09 [INFO][cache:0xc0001d62d0] Done checking OCSP staples
2020/01/15 19:22:11 [INFO] 216.168.130.82 - No such site at :80 (Remote: 103.89.252.22, Referer: )

5. What I already tried:

Restart.

Weird. I have never seen that before. Looks like something emitted by the Go standard library.

Anyway… I have no idea.

Is your network hardware failing?

It seems to happen with something related to IPv6.

Hmmm, that’s interesting. I’m always loathe to blame hardware, but I don’t see the problem on my backup server which is the same Mac/OS/Caddy setup. I’ll try switching them and see if the problem goes away. Thanks.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.