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

how to detect a timed-out connection, and avoid panic on client.AGReadDB #46

Closed
dataselfservice opened this issue Jun 10, 2021 · 1 comment · Fixed by #47
Closed

how to detect a timed-out connection, and avoid panic on client.AGReadDB #46

dataselfservice opened this issue Jun 10, 2021 · 1 comment · Fixed by #47

Comments

@dataselfservice
Copy link

Hi,

trying to reuse a connection client when accessing the same Address, Rack, Slot to avoid multiple Connect():

        handler = gos7.NewTCPClientHandler(key.TcpDevice, key.Rack, key.Slot)
        handler.Timeout = 20 * time.Second
        handler.IdleTimeout = 20 * time.Second
        if debug {
                c.handler.Logger = log.New(os.Stdout, "tcp: ", log.Llongfile)
        }               
        err = handler.Connect()
        if err != nil { 
                log.Printf("connect err: %v", err)
                return
        }       

        client = gos7.NewClient(c.handler)

then:

err = client.AGReadDB(req.Address, req.WordStart, req.WordSize, buf)
...

if the connection drops (or goes into timeout): client.AGReadDB(req.Address, req.WordStart, req.WordSize, buf) panics with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x3b5568]

goroutine 24 [running]:
github.com/robinson/gos7.(*tcpTransporter).Send(0x1c175c0, 0x1c1b300, 0x1f, 0x1f, 0x0, 0x0, 0x0, 0x0, 0x0)
        github.com/robinson/gos7@v0.0.0-20201216125248-2dd72fe148d3/tcpclient.go:117 +0x108
github.com/robinson/gos7.(*client).send(0x1c0d060, 0x1c62ce4, 0x1f, 0x1c1b300, 0x1dd70)
        github.com/robinson/gos7@v0.0.0-20201216125248-2dd72fe148d3/client.go:469 +0x44
github.com/robinson/gos7.(*client).readArea(0x1c0d060, 0x84, 0x5a, 0xc, 0x4, 0x2, 0x1c19124, 0x4, 0x4, 0x1, ...)
        github.com/robinson/gos7@v0.0.0-20201216125248-2dd72fe148d3/client.go:228 +0x2d0
github.com/robinson/gos7.(*client).AGReadDB(0x1c0d060, 0x5a, 0xc, 0x4, 0x1c19124, 0x4, 0x4, 0x0, 0x4)
        github.com/robinson/gos7@v0.0.0-20201216125248-2dd72fe148d3/client.go:76 +0x5c
...

Why is that panic-ing and how can I avoid that? E.g. detecting connection is dopped or invalid? Or reconnecting?

Cheers,
DataSeflService

@dataselfservice dataselfservice changed the title how to detect a timed-out connection, and avoid how to detect a timed-out connection, and avoid panic on client.AGReadDB Jun 10, 2021
@dataselfservice
Copy link
Author

Not sure this is best, but it at lease detects nil connection.

You might consider pulling this one: dataselfservice@2aa923f
as a fix.

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

Successfully merging a pull request may close this issue.

1 participant