mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
Add health-check agent recognition to avoid error logs (#4917)
Health-check connections now send a properly formatted auth message with a well-known peer ID instead of immediately closing. The server recognizes this peer ID and handles the connection gracefully with a debug log instead of error logs.
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
||||
|
||||
"github.com/coder/websocket"
|
||||
|
||||
"github.com/netbirdio/netbird/relay/healthcheck/peerid"
|
||||
"github.com/netbirdio/netbird/relay/server"
|
||||
"github.com/netbirdio/netbird/shared/relay"
|
||||
"github.com/netbirdio/netbird/shared/relay/messages"
|
||||
)
|
||||
|
||||
func dialWS(ctx context.Context, address url.URL) error {
|
||||
@@ -30,7 +32,18 @@ func dialWS(ctx context.Context, address url.URL) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to websocket: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.CloseNow()
|
||||
}()
|
||||
|
||||
authMsg, err := messages.MarshalAuthMsg(peerid.HealthCheckPeerID, peerid.DummyAuthToken)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal auth message: %w", err)
|
||||
}
|
||||
|
||||
if err := conn.Write(ctx, websocket.MessageBinary, authMsg); err != nil {
|
||||
return fmt.Errorf("failed to write auth message: %w", err)
|
||||
}
|
||||
|
||||
_ = conn.Close(websocket.StatusNormalClosure, "availability check complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user