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

ListenUnixgram runtime error #26

Closed
jonnsl opened this issue Feb 15, 2016 · 5 comments
Closed

ListenUnixgram runtime error #26

jonnsl opened this issue Feb 15, 2016 · 5 comments

Comments

@jonnsl
Copy link

jonnsl commented Feb 15, 2016

I'm trying to receive logs from nginx using unix sockets, but when nginx sends the first message, nothing happens, on the second message, the program crashes.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x28 pc=0x473ce6]

goroutine 6 [running]:
gopkg.in/mcuadros/go-syslog%2ev2.(*Server).goReceiveDatagrams.func1(0xc82008c090, 0x7feea6e0a448, 0xc82002e030)
    /home/jonnathan/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:275 +0x116
created by gopkg.in/mcuadros/go-syslog%2ev2.(*Server).goReceiveDatagrams
    /home/jonnathan/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:288 +0x11e

goroutine 1 [semacquire]:
sync.runtime_Semacquire(0xc82008c0cc)
    /usr/lib/go/src/runtime/sema.go:43 +0x26
sync.(*WaitGroup).Wait(0xc82008c0c0)
    /usr/lib/go/src/sync/waitgroup.go:126 +0xb4
gopkg.in/mcuadros/go-syslog%2ev2.(*Server).Wait(0xc82008c090)
    /home/jonnathan/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:241 +0x2d
main.main()
    /home/jonnathan/go/src/github.com/jonnsl/ssd/ssd.go:35 +0x311

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:1721 +0x1

goroutine 5 [chan receive]:
gopkg.in/mcuadros/go-syslog%2ev2.(*Server).goParseDatagrams.func1(0xc82008c090)
    /home/jonnathan/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:299 +0xc5
created by gopkg.in/mcuadros/go-syslog%2ev2.(*Server).goParseDatagrams
    /home/jonnathan/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:312 +0x92

goroutine 7 [chan receive]:
main.main.func1(0xc820014180)
    /home/jonnathan/go/src/github.com/jonnsl/ssd/ssd.go:30 +0x5d
created by main.main
    /home/jonnathan/go/src/github.com/jonnsl/ssd/ssd.go:33 +0x303

Here is my code:

    package main

    import (
        "fmt"
        "gopkg.in/mcuadros/go-syslog.v2"
        "log"
        "os"
    )

    const socket_path = "/var/run/ssd/ssd.sock"

    func main() {
        channel := make(syslog.LogPartsChannel)
        handler := syslog.NewChannelHandler(channel)

        removeSocket()
        defer removeSocket()

        server := syslog.NewServer()
        server.SetFormat(syslog.Automatic)
        server.SetHandler(handler)
        server.ListenUnixgram(socket_path)
        server.Boot()

        if err := os.Chmod(socket_path, 0222); err != nil {
            log.Fatal(err)
        }

        go func(channel syslog.LogPartsChannel) {
            for logParts := range channel {
                fmt.Println(logParts)
            }
        }(channel)

        server.Wait()
    }

    func removeSocket() {
        os.Remove(socket_path)
    }

ListenUDP works though

@abligh
Copy link
Contributor

abligh commented Feb 16, 2016

server.go:288 is actually a close brace, and the source of the exception is within kill. Perhaps you do not have an up to date go-syslog. Could you try updating to master?

@jonnsl
Copy link
Author

jonnsl commented Feb 17, 2016

without using gopkg.in, here is the new error message:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x28 pc=0x4749e9]

goroutine 6 [running]:
github.com/mcuadros/go-syslog.(*Server).goReceiveDatagrams.func1(0xc820092090, 0x7f0695cf94c0, 0xc82002e030)
    /home/jonnathan/go/src/github.com/mcuadros/go-syslog/server.go:326 +0x179
created by github.com/mcuadros/go-syslog.(*Server).goReceiveDatagrams
    /home/jonnathan/go/src/github.com/mcuadros/go-syslog/server.go:339 +0x11e

goroutine 1 [semacquire]:
sync.runtime_Semacquire(0xc8200920cc)
    /usr/lib/go/src/runtime/sema.go:43 +0x26
sync.(*WaitGroup).Wait(0xc8200920c0)
    /usr/lib/go/src/sync/waitgroup.go:126 +0xb4
github.com/mcuadros/go-syslog.(*Server).Wait(0xc820092090)
    /home/jonnathan/go/src/github.com/mcuadros/go-syslog/server.go:292 +0x2d
main.main()
    /home/jonnathan/go/src/github.com/jonnsl/ssd/ssd.go:35 +0x33e

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:1721 +0x1

goroutine 5 [chan receive]:
github.com/mcuadros/go-syslog.(*Server).goParseDatagrams.func1(0xc820092090)
    /home/jonnathan/go/src/github.com/mcuadros/go-syslog/server.go:350 +0xc5
created by github.com/mcuadros/go-syslog.(*Server).goParseDatagrams
    /home/jonnathan/go/src/github.com/mcuadros/go-syslog/server.go:363 +0x92

goroutine 7 [chan receive]:
main.main.func1(0xc820014180)
    /home/jonnathan/go/src/github.com/jonnsl/ssd/ssd.go:30 +0x5d
created by main.main
    /home/jonnathan/go/src/github.com/jonnsl/ssd/ssd.go:33 +0x330

abligh added a commit to abligh/go-syslog that referenced this issue Feb 17, 2016
With unix datagrams, apparently the address can be null. Use an empty
string as the address in this case.

Fixes mcuadros#26

Signed-off-by: Alex Bligh <alex@alex.org.uk>
@abligh
Copy link
Contributor

abligh commented Feb 17, 2016

Thanks for the report.

I think I have fixed this (my fault) on this branch:
https://github.com/abligh/go-syslog/tree/fix-null-datagram-address

You can try the fix locally with this patch:
abligh@429245c

If you confirm it fixes this issue then I will send a pull request.

@jonnsl
Copy link
Author

jonnsl commented Feb 17, 2016

It works perfectly, thanks!

@abligh
Copy link
Contributor

abligh commented Feb 17, 2016

Thanks. Pull Request #27 generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants