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

Revert "fix: close conn after read" #116

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.18
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/olekukonko/tablewriter v0.0.5
github.com/optimism-java/utp-go v0.0.0-20240531024756-00da67044c50
github.com/optimism-java/utp-go v0.0.0-20240309041853-b6b3a0dea581
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/protolambda/bls12-381-util v0.1.0
github.com/protolambda/zrnt v0.32.2
Expand All @@ -75,7 +75,7 @@ require (
golang.org/x/crypto v0.22.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/sys v0.19.0
golang.org/x/text v0.14.0
golang.org/x/time v0.5.0
golang.org/x/tools v0.20.0
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,6 @@ github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsq
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/optimism-java/utp-go v0.0.0-20240309041853-b6b3a0dea581 h1:ZxgrtI0xIw+clB32iDDDWaiTcCizTeN7rNyzH9YorPI=
github.com/optimism-java/utp-go v0.0.0-20240309041853-b6b3a0dea581/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/utp-go v0.0.0-20240530085325-d8dd9d262631 h1:01AecSuOSS6fsIU/oTVG/C70hIl3xPen99qy2hGr57w=
github.com/optimism-java/utp-go v0.0.0-20240530085325-d8dd9d262631/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/utp-go v0.0.0-20240531021243-e12d25b6be38 h1:t0gRqfM7wUrFyryagUpw4TmYY0DLt+rjPaBd92i+W2M=
github.com/optimism-java/utp-go v0.0.0-20240531021243-e12d25b6be38/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/utp-go v0.0.0-20240531024756-00da67044c50 h1:I1jGQkNEWq7BTFZkCJKLDrqFLC1jR3EC7jz3to4kpLg=
github.com/optimism-java/utp-go v0.0.0-20240531024756-00da67044c50/go.mod h1:DZ0jYzLzt4ZsCmhI/iqYgGFoNx45OfpEoKzXB8HVALQ=
github.com/optimism-java/zrnt v0.32.4-0.20240415084906-d9dbf06b32f7 h1:ZTQWXQ8xblCRUXhZs3h5qrBMSAHe8iNH7BG7a7IVFlI=
github.com/optimism-java/zrnt v0.32.4-0.20240415084906-d9dbf06b32f7/go.mod h1:A0fezkp9Tt3GBLATSPIbuY4ywYESyAuc/FFmPKg8Lqs=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
Expand Down Expand Up @@ -715,8 +709,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
4 changes: 0 additions & 4 deletions p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,6 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
}
// Read ALL the data from the connection until EOF and return it
data, err := io.ReadAll(conn)
conn.Close()
if err != nil {
p.Log.Error("failed to read from utp connection", "err", err)
return 0xff, nil, err
Expand Down Expand Up @@ -1044,7 +1043,6 @@ func (p *PortalProtocol) handleFindContent(id enode.ID, addr *net.UDPAddr, reque
connIdSend := connId.SendId()

go func(bctx context.Context) {
defer p.connIdGen.Remove(connId)
for {
select {
case <-bctx.Done():
Expand Down Expand Up @@ -1167,7 +1165,6 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
connIdSend := connId.SendId()

go func(bctx context.Context) {
defer p.connIdGen.Remove(connId)
for {
select {
case <-bctx.Done():
Expand All @@ -1192,7 +1189,6 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
// Read ALL the data from the connection until EOF and return it
var data []byte
data, err = io.ReadAll(conn)
conn.Close()
if err != nil {
p.Log.Error("failed to read from utp connection", "err", err)
return
Expand Down
40 changes: 18 additions & 22 deletions p2p/discover/portal_protocol_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package discover

import (
"context"
"crypto/rand"
"errors"
"fmt"
Expand All @@ -10,7 +11,6 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/portalnetwork/storage"
"github.com/prysmaticlabs/go-bitfield"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -79,7 +79,6 @@ func setupLocalPortalNode(addr string, bootNodes []*enode.Node) (*PortalProtocol
}
}
}
localNode.Set(enr.UDP(addr1.Port))

discV5, err := ListenV5(conn, localNode, discCfg)
if err != nil {
Expand Down Expand Up @@ -115,15 +114,6 @@ func TestPortalWireProtocolUdp(t *testing.T) {
assert.NoError(t, err)
time.Sleep(10 * time.Second)

node1.putCacheNodeId(node2.localNode.Node())
node1.putCacheNodeId(node3.localNode.Node())

node2.putCacheNodeId(node1.localNode.Node())
node2.putCacheNodeId(node3.localNode.Node())

node3.putCacheNodeId(node1.localNode.Node())
node3.putCacheNodeId(node2.localNode.Node())

udpAddrStr1 := fmt.Sprintf("%s:%d", node1.localNode.Node().IP(), node1.localNode.Node().UDP())
udpAddrStr2 := fmt.Sprintf("%s:%d", node2.localNode.Node().IP(), node2.localNode.Node().UDP())

Expand Down Expand Up @@ -244,9 +234,6 @@ func TestPortalWireProtocolUdp(t *testing.T) {
assert.Equal(t, largeTestContent, data)
}()
workGroup.Wait()
node1.Stop()
node2.Stop()
node3.Stop()
}

func TestPortalWireProtocol(t *testing.T) {
Expand Down Expand Up @@ -386,6 +373,23 @@ func TestPortalWireProtocol(t *testing.T) {
node3.Stop()
}

func TestCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())

go func(ctx context.Context) {
defer func() {
t.Log("goroutine cancel")
}()

time.Sleep(time.Second * 5)
}(ctx)

cancel()
t.Log("after main cancel")

time.Sleep(time.Second * 3)
}

func TestContentLookup(t *testing.T) {
node1, err := setupLocalPortalNode(":17777", nil)
assert.NoError(t, err)
Expand Down Expand Up @@ -424,10 +428,6 @@ func TestContentLookup(t *testing.T) {
res, _, err = node1.ContentLookup(nonExist, node1.toContentId(nonExist))
assert.Equal(t, ContentNotFound, err)
assert.Nil(t, res)

node1.Stop()
node2.Stop()
node3.Stop()
}

func TestTraceContentLookup(t *testing.T) {
Expand Down Expand Up @@ -497,8 +497,4 @@ func TestTraceContentLookup(t *testing.T) {
// res, _, err = node1.ContentLookup([]byte{0x2, 0x4})
// assert.Equal(t, ContentNotFound, err)
// assert.Nil(t, res)

node1.Stop()
node2.Stop()
node3.Stop()
}