Make socket proxy logging less chatty. (#405)

- Move data transfers to trace level.
- Move shutdown errors to warning.
- Only log listen, connect, and cleanup at info.
This commit is contained in:
J Logan
2025-11-12 09:45:30 -08:00
committed by GitHub
parent 01437a44a2
commit 6bf00ad796
2 changed files with 19 additions and 13 deletions
+15 -9
View File
@@ -254,7 +254,7 @@ extension SocketRelay {
closeOnDeinit: false
)
log?.info(
"initiating connection from host to guest",
"initiating connection from guest to host",
metadata: [
"vport": "\(port)",
"hostFd": "\(hostSocket.fileDescriptor)",
@@ -322,7 +322,7 @@ extension SocketRelay {
}
connSource.setCancelHandler {
self.log?.info(
self.log?.debug(
"host cancel received",
metadata: [
"hostFd": "\(hostConn.fileDescriptor)",
@@ -334,6 +334,12 @@ extension SocketRelay {
self.state.withLock { _ in
connSource.cancel()
if vsockConnectionSource.isCancelled {
self.log?.info(
"close file descriptors",
metadata: [
"hostFd": "\(hostConn.fileDescriptor)",
"guestFd": "\(guestFd)",
])
try? hostConn.close()
close(guestFd)
}
@@ -341,7 +347,7 @@ extension SocketRelay {
}
vsockConnectionSource.setCancelHandler {
self.log?.info(
self.log?.debug(
"guest cancel received",
metadata: [
"hostFd": "\(hostConn.fileDescriptor)",
@@ -377,14 +383,14 @@ extension SocketRelay {
log: Logger? = nil
) {
if source.data == 0 {
log?.info(
log?.debug(
"source EOF",
metadata: [
"sourceFd": "\(sourceFd)",
"dstFd": "\(destinationFd)",
])
if !source.isCancelled {
log?.info(
log?.debug(
"canceling DispatchSourceRead",
metadata: [
"sourceFd": "\(sourceFd)",
@@ -392,7 +398,7 @@ extension SocketRelay {
])
source.cancel()
if shutdown(destinationFd, SHUT_WR) != 0 {
log?.info(
log?.warning(
"failed to shut down reads",
metadata: [
"errno": "\(errno)",
@@ -406,7 +412,7 @@ extension SocketRelay {
}
do {
log?.debug(
log?.trace(
"source copy",
metadata: [
"sourceFd": "\(sourceFd)",
@@ -424,8 +430,8 @@ extension SocketRelay {
if !source.isCancelled {
source.cancel()
if shutdown(destinationFd, SHUT_RDWR) != 0 {
log?.info(
"failed to shut down destination",
log?.warning(
"failed to shut down destination after I/O error",
metadata: [
"errno": "\(errno)",
"sourceFd": "\(sourceFd)",
+4 -4
View File
@@ -268,7 +268,7 @@ extension VsockProxy {
// and no more EPOLLOUT events on the server fd
eofFromClient = true
if shutdown(serverFile.fileDescriptor, SHUT_WR) != 0 {
self.log?.info(
self.log?.warning(
"failed to shut down client reads",
metadata: [
"vport": "\(self.port)",
@@ -320,7 +320,7 @@ extension VsockProxy {
// and no more EPOLLOUT events on the client fd
eofFromServer = true
if shutdown(clientFile.fileDescriptor, SHUT_WR) != 0 {
self.log?.info(
self.log?.warning(
"failed to shut down server reads",
metadata: [
"vport": "\(self.port)",
@@ -353,7 +353,7 @@ extension VsockProxy {
) -> (Bool, Bool) {
do {
let (readBytes, writeBytes, action) = try OSFile.splice(from: &fromFile, to: &toFile)
log?.debug(
log?.trace(
"transferred data",
metadata: [
"description": "\(description)",
@@ -369,7 +369,7 @@ extension VsockProxy {
// we should see no more EPOLLIN events on the client fd
// and no more EPOLLOUT events on the server fd
if shutdown(toFile.fileDescriptor, SHUT_WR) != 0 {
log?.info(
log?.warning(
"failed to shut down reads",
metadata: [
"description": "\(description)",