-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Fixes and Logging #71
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package layer4 | ||
|
||
import ( | ||
"bytes" | ||
"net" | ||
"testing" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
func TestConnection_RecordAndRewind(t *testing.T) { | ||
in, out := net.Pipe() | ||
defer in.Close() | ||
defer out.Close() | ||
|
||
cx := WrapConnection(out, &bytes.Buffer{}, zap.NewNop()) | ||
defer cx.Close() | ||
|
||
matcherData := []byte("foo") | ||
consumeData := []byte("bar") | ||
|
||
buf := make([]byte, len(matcherData)) | ||
|
||
go func() { | ||
in.Write(matcherData) | ||
in.Write(consumeData) | ||
}() | ||
|
||
// 1st matcher | ||
|
||
cx.record() | ||
|
||
n, err := cx.Read(buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if n != len(matcherData) { | ||
t.Fatalf("expected to read %d bytes but got %d", len(matcherData), n) | ||
} | ||
if bytes.Compare(matcherData, buf) != 0 { | ||
t.Fatalf("expected %s but received %s", matcherData, buf) | ||
} | ||
|
||
cx.rewind() | ||
|
||
// 2nd matcher (reads same data) | ||
|
||
cx.record() | ||
|
||
n, err = cx.Read(buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if n != len(matcherData) { | ||
t.Fatalf("expected to read %d bytes but got %d", len(matcherData), n) | ||
} | ||
if bytes.Compare(matcherData, buf) != 0 { | ||
t.Fatalf("expected %s but received %s", matcherData, buf) | ||
} | ||
|
||
cx.rewind() | ||
|
||
// 1st consumer (no record call) | ||
|
||
n, err = cx.Read(buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if n != len(matcherData) { | ||
t.Fatalf("expected to read %d bytes but got %d", len(matcherData), n) | ||
} | ||
if bytes.Compare(matcherData, buf) != 0 { | ||
t.Fatalf("expected %s but received %s", matcherData, buf) | ||
} | ||
|
||
// 2nd consumer (reads other data) | ||
|
||
n, err = cx.Read(buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if n != len(consumeData) { | ||
t.Fatalf("expected to read %d bytes but got %d", len(consumeData), n) | ||
} | ||
if bytes.Compare(consumeData, buf) != 0 { | ||
t.Fatalf("expected %s but received %s", consumeData, buf) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would it be logged again? I don't see anywhere else we use the value
err
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be logged again in server.go#L109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, are you seeing that in your logs? How does
err
get returned from here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return statement is completely new to fix this:
You can see example logs of the processing not stopping in the initial post. When using
return err
instead one would see the double logging.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I follow so far, except I don't see where we are using
return err
anywhere. We always returnnextCopy.Handle(cx)
instead.(Sorry if I'm being a bit slow to understand.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are talking past each other :)
I included the comment to signify we are returning
nil
on purpose, because otherwise it may look like a bug.You are right we mostly return
nextCopy.Handle(cx)
except for exactly this case, since we want to stop the execution of the chain. But we already logged (handled) the error, so it is wrong to return the error (like it's often the case inif err != nil
blocks). Because the last return value from the chain will eventually appear in server.go#L106 and thus would get logged in server.go#L109 which we do not want because we already logged it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mholt, did you found the time to think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ydylla I'm so sorry for the delay on this PR. (It's not fair to you, that's for sure.) I was traveling this last week and also taking a little break from sprinting on Caddy stuff after the 2.6 release (to avoid burnout), and now I'm way behind on notifications. 😅 I'll be catching up soon!
If we can find another maintainer who is willing to review and approve this and other PRs, that might be a good idea so it's not always blocked by me. I feel bad about that! I might look around and see who would be willing to accept the invitation. This plugin just isn't nearly as active as the main Caddy project so it has fewer candidates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem at all, I understand that you are very busy. Don't feel bad, you are doing good work with caddy.
But you have to endure me pining you from time to time 😄
I just used the delay to clean up the commits and fix the failing tests in the l4socks module.