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

Do not set KeepAlive for non TCP connections #10

Merged
merged 1 commit into from
Jun 28, 2018

Conversation

riton
Copy link
Contributor

@riton riton commented Jun 27, 2018

With the latest version of master, when using a Unix socket to communicate with Livestatus, we face the following error:

2018/06/27 18:24:26 http: panic serving 127.0.0.1:56098: interface conversion: net.Conn is *net.UnixConn, not *net.TCPConn
goroutine 18 [running]:
net/http.(*conn).serve.func1(0xc4200e8c80)
        /opt/go/src/net/http/server.go:1721 +0xd0
panic(0x694f40, 0xc420070900)
[...]

This is due to the unconditional cast to a *net.TCPConn object in client.go.

This patch has been tested and fixes the issue.

Copy link
Owner

@vbatoufflet vbatoufflet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Indeed, I didn't check it using a UNIX socket for a while. Sorry for that.

I just made a few comments to your PR.

client.go Outdated
switch c.network {
case "tcp":
c.conn.(*net.TCPConn).SetKeepAlive(true)
break
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break is not needed in Go at the end of case blocks. Could you please remove them?

client.go Outdated
case "tcp":
c.conn.(*net.TCPConn).SetKeepAlive(true)
break
default:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default block is not mandatory either.

@riton
Copy link
Contributor Author

riton commented Jun 27, 2018

I've made the requested changes and pushed force.
I didn't know that break were optional in go, thanks !

@vbatoufflet vbatoufflet merged commit 2c303ee into vbatoufflet:master Jun 28, 2018
@vbatoufflet
Copy link
Owner

Just merged your PR. Thanks for the 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 this pull request may close these issues.

2 participants