wetware/pkg

Race condition in pubsub

lthibault opened this issue · 1 comments

Likely introduced with arena reuse in Cap'n Proto v3.0.0-alpha.10, but can't replicate.

First observed while working on

==================
WARNING: DATA RACE
Write at 0x00c000986308 by goroutine 138:
  capnproto.org/go/capnp/v3.alloc()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/message.go:356 +0x1d2
  capnproto.org/go/capnp/v3.NewCompositeList()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/list.go:62 +0xe4
  capnproto.org/go/capnp/v3/std/capnp/rpc.NewCapDescriptor_List()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/std/capnp/rpc/rpc.capnp.go:2406 +0xce
  capnproto.org/go/capnp/v3/std/capnp/rpc.Payload.NewCapTable()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/std/capnp/rpc/rpc.capnp.go:2179 +0x84
  capnproto.org/go/capnp/v3/rpc.(*Conn).fillPayloadCapTable()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/export.go:183 +0x14f
  capnproto.org/go/capnp/v3/rpc.(*answer).sendReturn()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/answer.go:236 +0x1ab
  capnproto.org/go/capnp/v3/rpc.(*answer).Return()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/answer.go:201 +0x29a
  capnproto.org/go/capnp/v3/server.(*Server).handleCall()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/server.go:214 +0x281
  capnproto.org/go/capnp/v3/server.(*Server).handleCalls.func2()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/server.go:182 +0x84
  capnproto.org/go/capnp/v3/server.(*Server).handleCalls()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/server.go:183 +0x1c4
  capnproto.org/go/capnp/v3/server.New.func1()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/server.go:122 +0x58

Previous read at 0x00c000986308 by goroutine 148:
  capnproto.org/go/capnp/v3.(*Segment).slice()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/segment.go:49 +0x5d
  capnproto.org/go/capnp/v3.(*Segment).readUint64()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/segment.go:65 +0x51
  capnproto.org/go/capnp/v3.(*Segment).readRawPointer()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/segment.go:69 +0x50
  capnproto.org/go/capnp/v3.(*Segment).resolveFarPointer()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/segment.go:235 +0x4f
  capnproto.org/go/capnp/v3.(*Segment).readPtr()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/segment.go:116 +0x75
  capnproto.org/go/capnp/v3.Struct.Ptr()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/struct.go:109 +0x119
  capnproto.org/go/capnp/v3.Transform()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/answer.go:579 +0x2ed
  capnproto.org/go/capnp/v3.resolution.ptr()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/answer.go:605 +0xfc
  capnproto.org/go/capnp/v3.resolution.client()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/answer.go:614 +0x96
  capnproto.org/go/capnp/v3.(*Answer).PipelineRecv()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/answer.go:392 +0x413
  capnproto.org/go/capnp/v3.(*Answer).PipelineRecv-fm()
      <autogenerated>:1 +0xc7
  capnproto.org/go/capnp/v3/server.queueCaller.PipelineRecv()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/answer.go:162 +0x322
  capnproto.org/go/capnp/v3/server.(*answerQueue).PipelineRecv()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/answer.go:136 +0xc9
  capnproto.org/go/capnp/v3/rpc.(*Conn).handleCall()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/rpc.go:834 +0x1992
  capnproto.org/go/capnp/v3/rpc.(*Conn).receive()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/rpc.go:538 +0x644
  capnproto.org/go/capnp/v3/rpc.(*Conn).receive-fm()
      <autogenerated>:1 +0x39
  capnproto.org/go/capnp/v3/rpc.(*Conn).backgroundTask.func1()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/rpc.go:198 +0x92
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /Users/lthibault/Go/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:75 +0x86

Goroutine 138 (running) created at:
  capnproto.org/go/capnp/v3/server.New()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/server/server.go:122 +0x544
  github.com/wetware/ww/internal/api/pubsub.Router_NewServer()
      /Users/lthibault/Go/src/github.com/wetware/ww/internal/api/pubsub/pubsub.capnp.go:804 +0xc9
  github.com/wetware/ww/internal/api/pubsub.Router_ServerToClient()
      /Users/lthibault/Go/src/github.com/wetware/ww/internal/api/pubsub/pubsub.capnp.go:810 +0x36
  github.com/wetware/ww/pkg/pubsub.NewJoiner()
      /Users/lthibault/Go/src/github.com/wetware/ww/pkg/pubsub/pubsub.go:42 +0x197
  github.com/wetware/ww/pkg/pubsub.(*Router).PubSub()
      /Users/lthibault/Go/src/github.com/wetware/ww/pkg/pubsub/server.go:28 +0x177
  github.com/wetware/ww/pkg/pubsub_test.TestMessageCopy()
      /Users/lthibault/Go/src/github.com/wetware/ww/pkg/pubsub/client_test.go:163 +0xd1
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1493 +0x47

Goroutine 148 (running) created at:
  golang.org/x/sync/errgroup.(*Group).Go()
      /Users/lthibault/Go/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:72 +0x12e
  capnproto.org/go/capnp/v3/rpc.NewConn()
      /Users/lthibault/Go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.11/rpc/rpc.go:164 +0x6d8
  github.com/wetware/ww/pkg/pubsub_test.TestMessageCopy()
      /Users/lthibault/Go/src/github.com/wetware/ww/pkg/pubsub/client_test.go:167 +0x32c
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1446 +0x216
  testing.(*T).Run.func1()
      /usr/local/go/src/testing/testing.go:1493 +0x47
==================
--- FAIL: TestMessageCopy (0.01s)
    testing.go:1319: race detected during execution of test
--- FAIL: TestPubSub (0.02s)
    client_test.go:68: got message 1 of 10
    client_test.go:68: got message 2 of 10
    client_test.go:68: got message 3 of 10
    client_test.go:68: got message 4 of 10
    client_test.go:68: got message 5 of 10
    client_test.go:68: got message 6 of 10
    client_test.go:68: got message 7 of 10
    client_test.go:68: got message 8 of 10
    client_test.go:68: got message 9 of 10
    client_test.go:68: got message 10 of 10
    testing.go:1319: race detected during execution of test
--- FAIL: TestSubscribe_cancel (0.03s)
    testing.go:1319: race detected during execution of test
FAIL
FAIL    github.com/wetware/ww/pkg/pubsub        1.446s
?       github.com/wetware/ww/pkg/server        [no test files]
FAIL

I think this was fixed by #66. Closing optimistically.