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

preserve buffer on reconnect() AND reconnect on connection reset by peer #291

Merged
merged 9 commits into from
Apr 14, 2017

Conversation

michaelshobbs
Copy link
Member

@michaelshobbs michaelshobbs commented Apr 12, 2017

turns out that in linux (alpine at least) a conn.Close() shows up as a syscall.ECONNRESET. so i included #287 here as well

closes #287 #277 #268 #253 #215 #107

josegonzalez
josegonzalez previously approved these changes Apr 12, 2017
Copy link
Member

@josegonzalez josegonzalez left a comment

Choose a reason for hiding this comment

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

Looks good to me, though I'll defer to @MattAitchison on golang usage ;)

// Read from connection
go func() {
defer close(ch)
defer close(dchan)
Copy link

Choose a reason for hiding this comment

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

nitpick

defer func() {
   close(ch)
   close(chan)
} ()

done := make(chan bool)
go func() {
defer close(logstream)
defer close(done)
Copy link

Choose a reason for hiding this comment

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

similar nitpick on grouping defer into func

}
}

func TestSyslogReconnectOnClose(t *testing.T) {
Copy link

Choose a reason for hiding this comment

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

This test is pretty intense.
I'd recommend breaking it down a little. Maybe move the go func() to named functions so they're just go someReallyClearFuncName()
Would make things a little more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@michaelshobbs michaelshobbs force-pushed the mh/chore/test-refactor branch from 476afe4 to 67bddd8 Compare April 12, 2017 19:46
select {
case <-done:
if maxMsgCount-1 != len(datac) {
t.Errorf("expected %v got %v", maxMsgCount-1, len(datac))
Copy link
Member

Choose a reason for hiding this comment

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

This should check for duplicate messages in addition to msg count.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@michaelshobbs michaelshobbs force-pushed the mh/chore/test-refactor branch from 67bddd8 to bf6dbd3 Compare April 12, 2017 20:57
@michaelshobbs michaelshobbs force-pushed the mh/chore/test-refactor branch 3 times, most recently from db840d1 to 2c4cf36 Compare April 13, 2017 17:22
@michaelshobbs michaelshobbs force-pushed the mh/chore/test-refactor branch from 2c4cf36 to ea5f535 Compare April 13, 2017 17:30

// NewConn returns a new testutil.Conn
func NewConn() *Conn {
// A connection consists of two pipes:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since a net.Pipe is a ReadWriter, it represents a duplex channel. I'm not sure you need two of these, which means you probably don't need a lot of the other code you have around these.

// LocalTCPServer tcp server for testing specific network errors
type LocalTCPServer struct {
lnmu sync.RWMutex
MockConn *Conn
Copy link
Contributor

Choose a reason for hiding this comment

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

The approach of mocking net connections is actually not terribly idiomatic. Because it's relatively easy in Go, most network tests in Go actually stand up a full network client/server instead of building mocks. This reduces a lot of code and better represents reality.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. If we can force specific connection errors (i.e. timeouts/resets/etc) then we can abandon this approach for sure. I'm playing with some stuff @MattAitchison sent over to see if we can use a "normal" net.Conn object.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to. And specific errors are specific cases for specific tests, which can minimally mock what's necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a lot of should happening here. Feel free to chime in with specific pointers.....

@michaelshobbs michaelshobbs changed the title preserve buffer on reconnect() preserve buffer on reconnect() AND reconnect on connection reset by peer Apr 14, 2017
@michaelshobbs
Copy link
Member Author

@progrium @MattAitchison updated this per our discussion

@michaelshobbs michaelshobbs merged commit f18e503 into master Apr 14, 2017
@michaelshobbs michaelshobbs deleted the mh/chore/test-refactor branch April 14, 2017 01:07
@tleyden
Copy link

tleyden commented Apr 20, 2017

When is this expected to get pushed up to gliderlabs/logspout:latest in dockerhub?

@michaelshobbs
Copy link
Member Author

This is v3.2.1 and latest now

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.

7 participants