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

race condition in TestProtoDowngrade #1144

Closed
marten-seemann opened this issue Jul 28, 2021 · 4 comments
Closed

race condition in TestProtoDowngrade #1144

marten-seemann opened this issue Jul 28, 2021 · 4 comments

Comments

@marten-seemann
Copy link
Contributor

See related quic-go issue: quic-go/quic-go#3239.

I'm not sure if we're using the API here correctly. Calling Read and CancelRead concurrently doesn't make a lot of sense.
It seems easy to fix though, so maybe we can get away with it?

=== RUN   TestProtoDowngrade
  ==================
  WARNING: DATA RACE
  Write at 0x00c0000f64f0 by goroutine 48:
    github.com/lucas-clemente/quic-go/internal/flowcontrol.(*baseFlowController).addBytesRead()
        /home/runner/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.19.3/internal/flowcontrol/base_flow_controller.go:71 +0xa4
    github.com/lucas-clemente/quic-go/internal/flowcontrol.(*streamFlowController).AddBytesRead()
        /home/runner/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.19.3/internal/flowcontrol/stream_flow_controller.go:90 +0x48
    github.com/lucas-clemente/quic-go.(*receiveStream).readImpl()
        /home/runner/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.19.3/receive_stream.go:177 +0x8a1
    github.com/lucas-clemente/quic-go.(*receiveStream).Read()
        /home/runner/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.19.3/receive_stream.go:84 +0x7c
    github.com/lucas-clemente/quic-go.(*stream).Read()
        <autogenerated>:1 +0x69
    github.com/libp2p/go-libp2p-quic-transport.(*stream).Read()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-quic-transport@v0.10.0/stream.go:18 +0x72
    github.com/libp2p/go-libp2p-swarm.(*Stream).Read()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_stream.go:57 +0x9c
    github.com/multiformats/go-multistream.(*byteReader).ReadByte()
        /home/runner/go/pkg/mod/github.com/multiformats/go-multistream@v0.2.2/multistream.go:471 +0x9b
    github.com/multiformats/go-varint.ReadUvarint()
        /home/runner/go/pkg/mod/github.com/multiformats/go-varint@v0.0.6/varint.go:80 +0xa1
    github.com/multiformats/go-multistream.lpReadBuf()
        /home/runner/go/pkg/mod/github.com/multiformats/go-multistream@v0.2.2/multistream.go:435 +0x93
    github.com/multiformats/go-multistream.ReadNextTokenBytes()
        /home/runner/go/pkg/mod/github.com/multiformats/go-multistream@v0.2.2/multistream.go:418 +0x4f
    github.com/multiformats/go-multistream.ReadNextToken()
        /home/runner/go/pkg/mod/github.com/multiformats/go-multistream@v0.2.2/multistream.go:407 +0x4dd
    github.com/multiformats/go-multistream.(*MultistreamMuxer).NegotiateLazy()
        /home/runner/go/pkg/mod/github.com/multiformats/go-multistream@v0.2.2/multistream.go:267 +0x491
    github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).newStreamHandler()
        /home/runner/work/go-libp2p/go-libp2p/p2p/host/basic/basic_host.go:389 +0x115
    github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).newStreamHandler-fm()
        /home/runner/work/go-libp2p/go-libp2p/p2p/host/basic/basic_host.go:378 +0x5e
    github.com/libp2p/go-libp2p-swarm.(*Conn).start.func1.1()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_conn.go:125 +0x122
  
  Previous read at 0x00c0000f64f0 by goroutine 95:
    github.com/lucas-clemente/quic-go/internal/flowcontrol.(*streamFlowController).Abandon()
        /home/runner/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.19.3/internal/flowcontrol/stream_flow_controller.go:100 +0x64
    github.com/lucas-clemente/quic-go.(*receiveStream).CancelRead()
        /home/runner/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.19.3/receive_stream.go:205 +0xb7
    github.com/lucas-clemente/quic-go.(*stream).CancelRead()
        <autogenerated>:1 +0x4d
    github.com/libp2p/go-libp2p-quic-transport.(*stream).Reset()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-quic-transport@v0.10.0/stream.go:36 +0x5d
    github.com/libp2p/go-libp2p-swarm.(*Stream).Reset()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_stream.go:88 +0x5b
    github.com/libp2p/go-libp2p-swarm.(*Conn).doClose()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_conn.go:75 +0x1d7
    github.com/libp2p/go-libp2p-swarm.(*Conn).doClose-fm()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_conn.go:61 +0x4a
    sync.(*Once).doSlow()
        /opt/hostedtoolcache/go/1.16.6/x64/src/sync/once.go:68 +0x109
    sync.(*Once).Do()
        /opt/hostedtoolcache/go/1.16.6/x64/src/sync/once.go:59 +0x68
    github.com/libp2p/go-libp2p-swarm.(*Conn).Close()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_conn.go:57 +0x65
    github.com/libp2p/go-libp2p-swarm.(*Swarm).ClosePeer()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm.go:505 +0x485
    github.com/libp2p/go-libp2p/p2p/host/basic.TestProtoDowngrade()
        /home/runner/work/go-libp2p/go-libp2p/p2p/host/basic/basic_host_test.go:529 +0x85d
    testing.tRunner()
        /opt/hostedtoolcache/go/1.16.6/x64/src/testing/testing.go:1193 +0x202
  
  Goroutine 48 (running) created at:
    github.com/libp2p/go-libp2p-swarm.(*Conn).start.func1()
        /home/runner/go/pkg/mod/github.com/libp2p/go-libp2p-swarm@v0.5.0/swarm_conn.go:112 +0x170
  
  Goroutine 95 (running) created at:
    testing.(*T).Run()
        /opt/hostedtoolcache/go/1.16.6/x64/src/testing/testing.go:1238 +0x5d7
    testing.runTests.func1()
        /opt/hostedtoolcache/go/1.16.6/x64/src/testing/testing.go:1511 +0xa6
    testing.tRunner()
        /opt/hostedtoolcache/go/1.16.6/x64/src/testing/testing.go:1193 +0x202
    testing.runTests()
        /opt/hostedtoolcache/go/1.16.6/x64/src/testing/testing.go:1509 +0x612
    testing.(*M).Run()
        /opt/hostedtoolcache/go/1.16.6/x64/src/testing/testing.go:1417 +0x3b3
    main.main()
        _testmain.go:77 +0x236
  ==================
      testing.go:1092: race detected during execution of test
@Stebalien
Copy link
Member

I'm not sure if we're using the API here correctly. Calling Read and CancelRead concurrently doesn't make a lot of sense.

Reset (which calls CancelRead) is the only way to interrupt an ongoing read (e.g., due to a context cancellation). We need to allow that.

@Stebalien
Copy link
Member

(reopen if I'm missing something)

@marten-seemann
Copy link
Contributor Author

Reopening because the PR in quic-go is not merged yet, and the update is not bubbled up yet. Also, there's an alternative fix in quic-go: quic-go/quic-go#3241.

@marten-seemann
Copy link
Contributor Author

This was fixed when we update go-libp2p-quic-transport to v0.12.0.

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 a pull request may close this issue.

2 participants