@@ -73,6 +73,7 @@ const (
7373
7474 pingThresholdMillis = 5 * 1000 // 5s
7575 arbitraryWaitForViaHandshake = 5 * time .Second
76+ markTNTAfterMillis = 20 * 1000 // TNT after 20s of no rcv after snd
7677
7778 removeViaOnErrors = false
7879
@@ -1391,16 +1392,18 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
13911392 }
13921393
13931394 s := TOK // assume err == nil
1394- if op == "r" && timedout (err ) {
1395- // if status is "up" but writes (op == "w") have not yet happened
1396- // then reads ("r") are expected to timeout; so ignore them
1397- if h .latestRx .Load () <= 0 {
1398- s = TNT // writes succeeded; but reads have never
1395+ if op == wg .Rcv && timedout (err ) {
1396+ lastSuccessfulRead := h .latestRx .Load ()
1397+ writeElapsedMs := h .latestTx .Load () - lastSuccessfulRead // may be negative
1398+ // if status is "up" but writes (Snd) have not yet happened
1399+ // then reads (Rcv) are expected to timeout; so ignore them
1400+ if lastSuccessfulRead <= 0 || writeElapsedMs > markTNTAfterMillis {
1401+ s = TNT // writes succeeded; but reads have never or not in the past 20s
13991402 } else {
1400- s = TZZ // wirtes and reads have succeeded in the past
1403+ s = TZZ // wirtes and reads have succeeded in the recent past
14011404 }
14021405 } else if err != nil {
1403- s = TKO
1406+ s = TKO // failing
14041407 }
14051408
14061409 if s == TOK {
@@ -1410,19 +1413,16 @@ func (h *wgtun) listener(op wg.PktDir, err error) {
14101413 h .latestTx .Store (now ())
14111414 }
14121415 writeElapsedMs := h .latestTx .Load () - h .latestRx .Load () // may be negative
1413- // if no reads in 20s since last write, then mark as unresponsive
1414- if writeElapsedMs > 20 * 1000 {
1416+ // if no reads since last write, mark as unresponsive
1417+ if writeElapsedMs > markTNTAfterMillis {
14151418 s = TNT
14161419 }
1417- } else if s == TKO {
1420+ } else if s != TUP {
14181421 if op == wg .Rcv {
14191422 h .errRx .Add (1 )
14201423 } else if op == wg .Snd {
14211424 h .errTx .Add (1 )
14221425 }
1423- }
1424-
1425- if s != TOK && s != TUP {
14261426 if n := h .remote .Load ().MaybeRefresh (); n > 0 {
14271427 log .I ("wg: %s (%s) listener: %s, state: %s; refreshed n domains: %d" ,
14281428 h .id , h .viaStatus (), op , pxstatus (s ), n )
0 commit comments