fix: use unixgram (DGRAM) instead of unix (STREAM) for socket output
Some checks failed
Build RPM Package / Build RPM Packages (CentOS 7, Rocky 8/9/10) (push) Has been cancelled

- Change net.DialTimeout from "unix" to "unixgram"
- Fixes "protocol wrong type for socket" error
- DGRAM sockets are connectionless, better suited for log shipping
- Update test to use net.ListenUnixgram instead of net.Listen

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Jacquin Antoine
2026-03-03 00:04:57 +01:00
parent 190ee5c964
commit 0b1df9ac6e
2 changed files with 20 additions and 19 deletions

View File

@ -259,6 +259,7 @@ type UnixSocketWriter struct {
errorCallback ErrorCallback
consecutiveFailures int
failuresMu sync.Mutex
networkType string // "unix" for STREAM, "unixgram" for DGRAM
}
// NewUnixSocketWriter creates a new UNIX socket writer with reconnection logic
@ -300,7 +301,8 @@ func NewUnixSocketWriterWithConfig(socketPath string, dialTimeout, writeTimeout
go w.processQueue()
// Try initial connection silently (socket may not exist yet - that's okay)
conn, err := net.DialTimeout("unix", socketPath, w.dialTimeout)
// Use unixgram (DGRAM) for connectionless UDP-like socket communication
conn, err := net.DialTimeout("unixgram", socketPath, w.dialTimeout)
if err == nil {
w.conn = conn
}
@ -399,7 +401,8 @@ func (w *UnixSocketWriter) writeWithReconnect(data []byte) error {
if w.conn != nil {
return nil
}
conn, err := net.DialTimeout("unix", w.socketPath, w.dialTimeout)
// Use unixgram (DGRAM) for connectionless UDP-like socket communication
conn, err := net.DialTimeout("unixgram", w.socketPath, w.dialTimeout)
if err != nil {
return fmt.Errorf("failed to connect to socket %s: %w", w.socketPath, err)
}