PrimeIntellect/SWE-rebench-V2-Filtered-Easy-Verified huggingface dataset:
Repository: pires/go-proxyproto (go)
Issue: Export underlying connection
Hi,

It would be good to export the underlying `proxyproto.Conn.conn` connection. 
Since proxyproto.Conn is not an `net.TCPConn`, and I need to cast it. 


Pull request description: exporting underlying Connection
this blocks implementing the listener in traefik

https://github.com/traefik/traefik/pull/7320

If you accept it, please create a new version tag, thank you!

closes #50 

Patch:
diff --git a/protocol.go b/protocol.go
index a686e8e..dea810d 100644
--- a/protocol.go
+++ b/protocol.go
@@ -147,6 +147,24 @@ func (p *Conn) RemoteAddr() net.Addr {
 	return p.header.SourceAddr
 }
 
+// TCPConn returns is the underlying connection as TCPConn
+func (p *Conn) TCPConn() (conn *net.TCPConn, ok bool) {
+	conn, ok = p.conn.(*net.TCPConn)
+	return
+}
+
+// UnixConn returns is the underlying connection as UnixConn
+func (p *Conn) UnixConn() (conn *net.UnixConn, ok bool) {
+	conn, ok = p.conn.(*net.UnixConn)
+	return
+}
+
+// UDPConn returns is the underlying connection as UDPConn
+func (p *Conn) UDPConn() (conn *net.UDPConn, ok bool) {
+	conn, ok = p.conn.(*net.UDPConn)
+	return
+}
+
 // SetDeadline wraps original conn.SetDeadline
 func (p *Conn) SetDeadline(t time.Time) error {
 	return p.conn.SetDeadline(t)


Test patch:
diff --git a/protocol_test.go b/protocol_test.go
index 025b485..429cee7 100644
--- a/protocol_test.go
+++ b/protocol_test.go
@@ -470,6 +470,46 @@ func TestReadingIsRefusedOnErrorWhenLocalAddrRequestedFirst(t *testing.T) {
 	}
 }
 
+func Test_ConnectionCasts(t *testing.T) {
+	l, err := net.Listen("tcp", "127.0.0.1:0")
+	if err != nil {
+		t.Fatalf("err: %v", err)
+	}
+
+	policyFunc := func(upstream net.Addr) (Policy, error) { return REQUIRE, nil }
+
+	pl := &Listener{Listener: l, Policy: policyFunc}
+
+	go func() {
+		conn, err := net.Dial("tcp", pl.Addr().String())
+		if err != nil {
+			t.Fatalf("err: %v", err)
+		}
+		defer conn.Close()
+		conn.Write([]byte("ping"))
+	}()
+
+	conn, err := pl.Accept()
+	if err != nil {
+		t.Fatalf("err: %v", err)
+	}
+	defer conn.Close()
+
+	proxyprotoConn := conn.(*Conn)
+	_, ok := proxyprotoConn.TCPConn()
+	if !ok {
+		t.Fatal("err: should be a tcp connection")
+	}
+	_, ok = proxyprotoConn.UDPConn()
+	if ok {
+		t.Fatal("err: should be a tcp connection not udp")
+	}
+	_, ok = proxyprotoConn.UnixConn()
+	if ok {
+		t.Fatal("err: should be a tcp connection not unix")
+	}
+}
+
 func Test_ConnectionErrorsWhenHeaderValidationFails(t *testing.T) {
 	l, err := net.Listen("tcp", "127.0.0.1:0")
 	if err != nil {
Repository: elixir-grpc/grpc (elixir)
Issue: Passing a nil channel to GRPC.Stub function errors on compressor
**Describe the bug**
If you pass nil to a GRPC.Stub function rather than a channel as expected, it will fail on `lib/grpc/stub:251: key :compressor not found in: nil`

**To Reproduce**
Steps to reproduce the behavior:
Call any RPC stub function with a nil channel as the first argument

**Expected behavior**
It should give a nice error message or a match error for the appropriate type, rather than an inadvertent error


Pull request description: Pattern match on channel on stub functions
Provides a better error for invalid argument. Closes #353 

Patch:
diff --git a/lib/grpc/stub.ex b/lib/grpc/stub.ex
index 659ceaf..b96ad51 100644
--- a/lib/grpc/stub.ex
+++ b/lib/grpc/stub.ex
@@ -78,7 +78,7 @@ defmodule GRPC.Stub do
         }
 
         if req_stream do
-          def unquote(String.to_atom(func_name))(channel, opts \\ []) do
+          def unquote(String.to_atom(func_name))(%GRPC.Channel{} = channel, opts \\ []) do
             GRPC.Stub.call(
               unquote(service_mod),
               unquote(Macro.escape(rpc)),
@@ -88,7 +88,7 @@ defmodule GRPC.Stub do
             )
           end
         else
-          def unquote(String.to_atom(func_name))(channel, request, opts \\ []) do
+          def unquote(String.to_atom(func_name))(%GRPC.Channel{} = channel, request, opts \\ []) do
             GRPC.Stub.call(
               unquote(service_mod),
               unquote(Macro.escape(rpc)),


Test patch:
diff --git a/test/grpc/integration/stub_test.exs b/test/grpc/integration/stub_test.exs
index b497003..d24cdc6 100644
--- a/test/grpc/integration/stub_test.exs
+++ b/test/grpc/integration/stub_test.exs
@@ -68,6 +68,14 @@ defmodule GRPC.Integration.StubTest do
     end)
   end
 
+  test "invalid channel function clause error" do
+    req = Helloworld.HelloRequest.new(name: "GRPC")
+
+    assert_raise FunctionClauseError, ~r/Helloworld.Greeter.Stub.say_hello/, fn ->
+      Helloworld.Greeter.Stub.say_hello(nil, req)
+    end
+  end
+
   test "returns error when timeout" do
     run_server(SlowServer, fn port ->
       {:ok, channel} = GRPC.Stub.connect("localhost:#{port}")