Passer au contenu

Nous améliorons nos opérations pour mieux vous servir. Les commandes sont expédiées normalement depuis Laval, QC. Questions? Contactez-nous

Bitcoin accepté au paiement  |  Expédié depuis Laval, QC, Canada  |  Soutien expert depuis 2016

Stratum connection interrupted Warning

PiAxe – Pyminer Stratum Connection Interrupted

The PiAxe's Python `pyminer` process logs `Stratum connection interrupted` and systemd restarts the service every few minutes. The BM1366 hashboard is fine — the TCP socket to the pool is being torn down by NAT idle timeouts, WiFi deauths, missing TCP keepalive in the stratum client, DNS flapping, pool-side rate limits, or a wedged BM1366 UART cascading into the socket layer.

Warning — Should be addressed soon

Affected Models: PiAxe (Raspberry Pi Zero 2 W / 3 / 4 / 5 + BM1366 or BM1368 hashboard hat); reference `shufps/piaxe-miner` Python stack

Symptoms

  • `journalctl -u pyminer` shows repeated `Stratum connection interrupted` or `stratum_recv_line: connection closed by peer` every 2-30 minutes
  • `systemctl status pyminer` shows `active (running)` but `Main PID` changes every few minutes (systemd is auto-restarting)
  • Pool dashboard shows a sawtooth online/offline pattern for the PiAxe worker, with share rate dipping to zero between reconnects
  • `dmesg` contains WiFi events: `wlan0: deauthenticated`, `wlan0: disconnected`, or `brcmfmac: retrying command`
  • BM1366 hat LED stays lit and the chip stays warm (~55-65 °C) — network-layer drop, not a chip fault
  • `pyminer` stdout contains Python tracebacks: `socket.timeout`, `ConnectionResetError`, `BrokenPipeError`, or `OSError: [Errno 104]`
  • `ping <pool-host>` from the Pi shows sporadic 2000+ ms spikes or 3-5% packet loss correlated with log drops
  • After `pyminer` auto-restart, first-share latency climbs for ~60 seconds while it re-subscribes to stratum
  • Under `iftop` / `vnstat`, the Pi shows near-zero bytes to the pool host between drops (confirmed idle, not flooded)
  • Hashrate reported on the PiAxe dashboard flatlines at nominal (~450-500 GH/s on BM1366) while the pool shows a lower effective hashrate due to lost work windows
  • `conntrack -E -p tcp` on the Pi or router shows `DESTROY` events on the pool connection, confirming NAT state-table expiry

Step-by-Step Fix

1

SSH to the Pi (or attach keyboard + monitor). Edit `/etc/systemd/system/pyminer.service` with `sudo nano`. Under `[Service]` add `RestartSec=60` so systemd waits 60 seconds before restarting after a crash — prevents the pool from rate-limiting or IP-banning the Pi for reconnect spam. Save, run `sudo systemctl daemon-reload` then `sudo systemctl restart pyminer`. Watch `journalctl -u pyminer -f` for 10 minutes and confirm restart cadence is now ≥60 seconds when drops occur.

2

Lock the Pi to 2.4 GHz WiFi and disable power save. Edit `/etc/wpa_supplicant/wpa_supplicant.conf`, add `freq_list=2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462` inside your `network={}` block. Run `sudo iw dev wlan0 set power_save off` and persist via cron `@reboot`. Reboot. Run `iwconfig wlan0` — confirm `Power Management:off`. Broadcom `brcmfmac` power-save is a chronic PiAxe-drop culprit; disabling it resolves many cases outright.

3

Switch DNS to Cloudflare + Quad9 on the Pi. Edit `/etc/dhcpcd.conf` and add `static domain_name_servers=1.1.1.1 9.9.9.9` under your `interface wlan0` block. Restart networking. Run `dig <pool-host>` and confirm consistent <50 ms resolution. Flaky ISP DNS extends every stratum reconnect window and can fail reconnects outright; eliminating it shortens or eliminates the outage.

4

Drop an Ethernet link onto the Pi. For a Pi 4 / Pi 5 use the onboard port. For a Pi Zero 2 W, a $10-20 USB-OTG-to-Ethernet adapter works. A wired PiAxe almost never exhibits this failure mode. Set DHCP on the router or configure static IP via `/etc/dhcpcd.conf`. Confirm with `ip addr show eth0`. This is the single highest reliability-per-dollar upgrade for any PiAxe operator.

5

Switch to a permissive solo pool for diagnosis. Edit `~/piaxe-miner/config.yaml`: `pool: public-pool.io`, `port: 21496`, `user: <your-on-chain-BTC-address>`, `password: x`. Restart `pyminer`. If the interrupt cadence disappears, your original pool has tighter timeout/policy defaults. If drops continue on public-pool.io, the problem is upstream of the pool — on the Pi, the network, or the Python stack.

6

Add TCP keepalive in `pyminer`'s socket layer. Edit `~/piaxe-miner/stratum.py`. After the socket is created (`socket.socket(socket.AF_INET, socket.SOCK_STREAM)`), add: `sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)`, `sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 30)`, `sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 10)`, `sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 3)`. Kernel sends a keepalive probe after 30 s idle, repeats every 10 s, gives up after 3 misses. Refreshes NAT state tables and kills zombie half-open sockets. Restart `pyminer` and monitor 24 h.

7

Add a hard Python recv timeout. In the same `stratum.py`, call `sock.settimeout(60)` on the connected socket. `recv()` now raises `socket.timeout` after 60 s of silence instead of blocking for ~15 minutes on the OS default. The main loop's `except` catches the timeout, reconnects immediately, and you stop losing share windows to zombie sockets the kernel hasn't yet given up on.

8

Harden the systemd unit. Under `[Service]` set `Restart=on-failure`, `RestartSec=30`, `StartLimitBurst=10`, `StartLimitIntervalSec=600`, `TimeoutStartSec=60`. Under `[Unit]` add `After=network-online.target` and `Wants=network-online.target`. `pyminer` now waits for real network readiness, backs off on restart storms, and gives up gracefully rather than thrashing into a pool ban. `sudo systemctl daemon-reload && sudo systemctl restart pyminer`.

9

Install a local DNS cache. `sudo apt install systemd-resolved && sudo systemctl enable --now systemd-resolved`. Verify with `resolvectl status`. A cached resolver shortens reconnect windows — without it, every reconnect hits upstream DNS, and a slow response extends the outage. Belt-and-suspenders alongside Step 3's static DNS assignment.

10

Tune kernel TCP keepalive as a baseline across all sockets on the Pi. Append to `/etc/sysctl.d/99-piaxe-tcp.conf`: `net.ipv4.tcp_keepalive_time=60`, `net.ipv4.tcp_keepalive_intvl=10`, `net.ipv4.tcp_keepalive_probes=3`. Apply with `sudo sysctl --system`. Step 6's per-socket settings are stronger but baseline sanity helps every TCP connection the host makes.

11

Build a custom `pyminer` with application-layer stratum keepalive. Add a background thread that sends `mining.suggest_difficulty` or `mining.get_transactions` every 90 s — benign, pool-legal, and keeps the socket in active-traffic state so NAT never ages it out. Reference https://en.bitcoin.it/wiki/Stratum_mining_protocol for valid methods. File a PR upstream to `shufps/piaxe-miner` so others benefit from the fix.

12

Evaluate `cgminer` / `bfgminer` as an alternative stratum client. They have mature reconnect, backoff, fallback pool rotation, near-zero CPU overhead. The lift is porting the PiAxe's Python BM1366 driver into `cgminer`'s C driver layer — real engineering effort. For most operators, hardening `pyminer` (Steps 1-10) is the right call. Track https://github.com/luke-jr/bfgminer stratum implementation as reference.

13

Pipe `pyminer` stdout/stderr to a rotated logfile. In the systemd unit add `StandardOutput=append:/var/log/pyminer.log` and `StandardError=append:/var/log/pyminer.log`. Create `/etc/logrotate.d/pyminer` with `daily`, `rotate 7`, `compress`, `missingok`, `notifempty`. When a mysterious drop happens, you have the full trace — not just the 200 lines `journalctl` kept.

14

Capture a pcap of the stratum session across 2-3 drop cycles. On the Pi: `sudo tcpdump -i wlan0 -w /tmp/stratum.pcap host <pool-host>`. Let it run 30-60 minutes. Copy the pcap to a desktop and open in Wireshark. You'll see the exact FIN/RST sequence, who initiated the close, and how long the TCP session was idle before teardown. Nuclear diagnostic — if pool is sending FIN and the Pi is healthy, it's pool-side policy; if Pi is sending RST during a WiFi dip, it's the radio.

15

Pin `piaxe-miner` to a known-good commit. Some forks have a `last_activity` tracker in `stratum.py` that resets on RX-only events and misses half-open cases. Review the commit history: `cd ~/piaxe-miner && git log --oneline stratum.py`. Check out a commit that ran stable for you, pin it in your deploy script. Reference https://github.com/pooler/cpuminer/issues/124 for the C-miner parent issue pattern and its patch history.

16

If `pyminer` restarts correlate with BM1366 UART wedges (see [PiAxe BM1366 UART communication error](https://d-central.tech/asic-troubleshooting/piaxe-bm1366-serial-communication-error/)), the stratum drop is a downstream symptom — the chip is hanging and the socket watchdog trips. Confirm by running `stty -F /dev/serial0 115200 raw -echo && cat /dev/serial0` for 5 seconds. If `cat` hangs, UART is wedged; reboot and re-check `/boot/cmdline.txt` for conflicting `console=serial0` entries, and `/boot/config.txt` for `dtoverlay=disable-bt` or equivalent.

17

Stop DIY and escalate. You've applied Steps 1-8, captured a pcap showing pool-side FIN on a clean network path, and a control PiAxe on the same network behaves the same. Open a D-Central support ticket at https://d-central.tech/contact/ with pcap, `journalctl -u pyminer -n 500`, and redacted `config.yaml`. For upstream firmware/Python bugs, file at https://github.com/shufps/piaxe-miner/issues. D-Central will triage the config and hardware side in one ticket.

When to Seek Professional Repair

If the steps above do not resolve the issue, or if you are not comfortable performing these repairs yourself, professional service is recommended. Attempting advanced repairs without proper equipment can cause further damage.

Related Error Codes

Still Having Issues?

Our team of Bitcoin Mining Hackers has been repairing ASIC miners since 2016. We have seen it all and fixed it all. Get a professional diagnosis.