DuoSoftware / log4go

Automatically exported from code.google.com/p/log4go
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

udp SocketLogger hangs unrecoverably on socket.Write() error #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
0. Logging is set up as follows:

var (
    logger = make(l4g.Logger)
)
type Logger struct {
}
func (l *Logger) Write(d []byte) (int, error) {
    s := string(d)
    logger.Info(s)
    return len(d), nil
}
func init(){
    log.SetFlags(0)
    log.SetOutput(&Logger{})
// host, port are non-local btw
        logger.AddFilter("network", l4g.FINEST, l4g.NewSocketLogWriter("udp", fmt.Sprintf("%s:%d", host, port)))
}

1. Start a udp socket logger in process A to a process B ( as above )   
2. Start logging in A
    logger.Info(s)
3. Stop B

What is the expected output? What do you see instead?
Expected:
That logging in A continues as normal. but nothing reach B ( as it is down )
Instead:

All goroutines that do any logging end up hanging like this:

goroutine 75334584 [semacquire]:
sync.runtime_Semacquire(0xc21001f194)
    /usr/local/go/src/pkg/runtime/sema.goc:199 +0x30
sync.(*Mutex).Lock(0xc21001f190)
    /usr/local/go/src/pkg/sync/mutex.go:66 +0xd6
log.(*Logger).Output(0xc21001f190, 0x2, 0xc2102649c0, 0x1c, 0x0, ...)
    /usr/local/go/src/pkg/log/log.go:134 +0x95
log.Printf(0x7f8e90, 0x16, 0x7f2b541c7eb8, 0x1, 0x1)
    /usr/local/go/src/pkg/log/log.go:276 +0x7d

while a single goroutine hangs on:

code.google.com/p/log4go.SocketLogWriter.LogWrite(0xc210068420, 0xc2109e5c40)
    .../lib/src/code.google.com/p/log4go/socklog.go:17 +0x3a
code.google.com/p/log4go.Logger.intLogf(0xc2101baab0, 0x4, 0xc2102a7cd0, 0x48, 
0x0, ...)
    .../lib/src/code.google.com/p/log4go/log4go.go:223 +0x3aa
code.google.com/p/log4go.Logger.Info(0xc2101baab0, 0x69dbe0, 0xc210357540, 0x0, 
0x0, ...)
    .../lib/src/code.google.com/p/log4go/log4go.go:405 +0x142
main.(*Logger).Write(0xbafcc8, 0xc210181600, 0x48, 0x100, 0xba6f80, ...)
    .../lib/src/redistasker/deleter/logger.go:24 +0x94
log.(*Logger).Output(0xc21001f190, 0x2, 0xc2102a7230, 0x47, 0x0, ...)
    /usr/local/go/src/pkg/log/log.go:153 +0x405
log.Printf(0x8168d0, 0x1d, 0x7f2b541cbf60, 0x3, 0x3)

This is because the goroutine that reads from the channel and writes to the 
socket has returned.

Its probably the same for a tcp socket. I've only tested udp though

Original issue reported on code.google.com by Kimmeh on 23 Jan 2014 at 2:15