mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 20:26:47 +02:00
The Tailscale CLI has some methods to watch the IPN bus for messages, say, the current netmap (`tailscale debug netmap`). The Tailscale daemon supports this using a streaming HTTP response. Sometimes, the client can close its connection abruptly -- due to an interruption, or in the case of `debug netmap`, intentionally after consuming one message. If the server daemon is writing a response as the client closes its end of the socket, the daemon typically encounters a "broken pipe" error. The "Watch IPN Bus" handler currently logs such errors after they're propagated by a JSON encoding/writer helper. Since the Tailscale CLI nominally closes its socket with the daemon in this slightly ungraceful way (viz. `debug netmap`), stop logging these broken pipe errors as far as possible. This will help avoid confounding users when they scan backend logs. Updates #18477 Signed-off-by: Amal Bansode <amal@tailscale.com>
34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
package magicsock
|
|
|
|
import (
|
|
"errors"
|
|
"syscall"
|
|
|
|
"tailscale.com/net/neterror"
|
|
)
|
|
|
|
// shouldRebind returns if the error is one that is known to be healed by a
|
|
// rebind, and if so also returns a resason string for the rebind.
|
|
func shouldRebind(err error) (ok bool, reason string) {
|
|
switch {
|
|
// EPIPE/ENOTCONN are common errors when a send fails due to a closed
|
|
// socket. There is some platform and version inconsistency in which
|
|
// error is returned, but the meaning is the same.
|
|
case neterror.IsClosedPipeError(err):
|
|
return true, "broken-pipe"
|
|
|
|
// EPERM is typically caused by EDR software, and has been observed to be
|
|
// transient, it seems that some versions of some EDR lose track of sockets
|
|
// at times, and return EPERM, but reconnects will establish appropriate
|
|
// rights associated with a new socket.
|
|
case errors.Is(err, syscall.EPERM):
|
|
return true, "operation-not-permitted"
|
|
}
|
|
return false, ""
|
|
}
|