Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alert: Check UDPbuffer-size #11360

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const (
// health checks
CheckFDLimit
CheckFvmConcurrency
CheckUDPBufferSize
LegacyMarketsEOL

// libp2p
Expand Down Expand Up @@ -169,6 +170,7 @@ func defaults() []Option {

Override(CheckFDLimit, modules.CheckFdLimit(build.DefaultFDLimit)),
Override(CheckFvmConcurrency, modules.CheckFvmConcurrency()),
Override(CheckUDPBufferSize, modules.CheckUDPBufferSize(2048*1024)),

Override(new(system.MemoryConstraints), modules.MemoryConstraints),
Override(InitMemoryWatchdog, modules.MemoryWatchdog),
Expand Down
65 changes: 65 additions & 0 deletions node/modules/alerts.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package modules

import (
"net"
"os"
"strconv"
"syscall"

"github.com/filecoin-project/lotus/journal/alerting"
"github.com/filecoin-project/lotus/lib/ulimit"
Expand Down Expand Up @@ -35,6 +37,69 @@ func CheckFdLimit(min uint64) func(al *alerting.Alerting) {
}
}

func CheckUDPBufferSize(wanted int) func(al *alerting.Alerting) {
return func(al *alerting.Alerting) {
conn, err := net.Dial("udp", "localhost:0")
if err != nil {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to create UDP connection",
"error": err.Error(),
})
return
}
defer func() {
if err := conn.Close(); err != nil {
log.Warnf("Failed to close connection: %s", err)
}
}()

udpConn, ok := conn.(*net.UDPConn)
if !ok {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to cast connection to UDPConn",
})
return
}

file, err := udpConn.File()
if err != nil {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to get file descriptor from UDPConn",
"error": err.Error(),
})
return
}
defer func() {
if err := file.Close(); err != nil {
log.Warnf("Failed to close file: %s", err)
}
}()

size, err := syscall.GetsockoptInt(int(file.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
if err != nil {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]string{
"message": "Failed to get UDP buffer size",
"error": err.Error(),
})
return
}

if size < wanted {
alert := al.AddAlertType("process", "udp-buffer-size")
al.Raise(alert, map[string]interface{}{
"message": "UDP buffer size is low",
"current_size": size,
"wanted_size": wanted,
"help": "See https://github.com/quic-go/quic-go/wiki/UDP-Buffer-Sizes for details.",
})
}
}
}

func LegacyMarketsEOL(al *alerting.Alerting) {
// Add alert if lotus-miner legacy markets subsystem is still in use
alert := al.AddAlertType("system", "EOL")
Expand Down