go-capnp icon indicating copy to clipboard operation
go-capnp copied to clipboard

Bootstrap with expired capability deadlocks

Open lthibault opened this issue 1 year ago • 0 comments

Passing an expired capability to rpc.Conn.Bootstrap causes a deadlock. To reproduce, run TestHandleReturn_regression in the bug/bootstrap-panic branch. The second subtest relates to the present issue.

func TestDeadlock(t *testing.T) {
	p1, p2 := transport.NewPipe(1)

	srv := testcp.PingPong_ServerToClient(pingPongServer{}, nil)
	conn1 := rpc.NewConn(rpc.NewTransport(p2), &rpc.Options{
		BootstrapClient: srv.Client,
	})
	defer conn1.Close()

	conn2 := rpc.NewConn(rpc.NewTransport(p1), nil)
	defer conn2.Close()

	// create an EXPIRED context
	ctx, cancel := context.WithCancel(context.Background())
	cancel()

	// NOTE: bootstrap with expired context
	pp := testcp.PingPong{Client: conn2.Bootstrap(context.Background())}
	defer pp.Release()

	f, release := pp.EchoNum(ctx, func(ps testcp.PingPong_echoNum_Params) error {
		ps.SetN(42)
		return nil
	})
	defer release()

	_, err := f.Struct()  // DEADLOCK
	assert.NoError(t, err)
}
panic: test timed out after 10s

goroutine 50 [running]:
testing.(*M).startAlarm.func1()
	/usr/local/go/src/testing/testing.go:2029 +0x8e
created by time.goFunc
	/usr/local/go/src/time/sleep.go:176 +0x32

goroutine 1 [chan receive]:
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1405 +0x4a5
testing.tRunner(0xc0001076c0, 0xc000165c60)
	/usr/local/go/src/testing/testing.go:1445 +0x13b
testing.runTests(0xc0001350e0?, {0x14549e0, 0x18, 0x18}, {0x100e3e5?, 0x1014806?, 0x145a000?})
	/usr/local/go/src/testing/testing.go:1837 +0x457
testing.(*M).Run(0xc0001350e0)
	/usr/local/go/src/testing/testing.go:1719 +0x5d9
capnproto.org/go/capnp/v3/rpc_test.TestMain(0x1040531?)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/level0_test.go:43 +0xbb
main.main()
	_testmain.go:99 +0x1d3

goroutine 35 [chan receive]:
testing.(*T).Run(0xc000107860, {0x12965e7?, 0x0?}, 0xc0001132b0)
	/usr/local/go/src/testing/testing.go:1487 +0x37a
capnproto.org/go/capnp/v3/rpc_test.TestHandleReturn_regression(0x0?)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/level0_test.go:1804 +0x297
testing.tRunner(0xc000107860, 0x12a7430)
	/usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1486 +0x35f

goroutine 36 [select]:
capnproto.org/go/capnp/v3/internal/mpsc.(*Rx[...]).Recv(0xc00012c2e0, {0x12f46b8, 0xc00016eb00})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/internal/mpsc/mpsc.go:88 +0x7f
capnproto.org/go/capnp/v3/server.(*Server).handleCalls(0xc000198230, {0x12f46b8?, 0xc00016eb00})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/server/server.go:175 +0x5c
created by capnproto.org/go/capnp/v3/server.New
	/Users/lthibault/Go/src/capnproto.org/go/capnp/server/server.go:135 +0x325

goroutine 37 [select]:
capnproto.org/go/capnp/v3/internal/mpsc.(*Rx[...]).Recv(0xc00012c310, {0x12f46b8, 0xc00016ebc0})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/internal/mpsc/mpsc.go:88 +0x7f
capnproto.org/go/capnp/v3/rpc.(*Conn).send(0xc000136b40)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:426 +0x48
capnproto.org/go/capnp/v3/rpc.(*Conn).backgroundTask.func1()
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:191 +0x6b
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x8d

goroutine 38 [select]:
capnproto.org/go/capnp/v3/rpc/transport.(*pipe).Decode(0x0?, {0x12f46b8, 0xc00016ebc0})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/transport/pipe.go:64 +0x86
capnproto.org/go/capnp/v3/rpc/transport.(*transport).RecvMessage(0x0?, {0x12f46b8?, 0xc00016ebc0?})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/transport/transport.go:166 +0xf6
capnproto.org/go/capnp/v3/rpc.(*Conn).receive(0xc000136b40)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:444 +0x78
capnproto.org/go/capnp/v3/rpc.(*Conn).backgroundTask.func1()
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:191 +0x6b
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x8d

goroutine 39 [semacquire]:
sync.runtime_Semacquire(0x0?)
	/usr/local/go/src/runtime/sema.go:56 +0x25
sync.(*WaitGroup).Wait(0x0?)
	/usr/local/go/src/sync/waitgroup.go:136 +0x52
golang.org/x/sync/errgroup.(*Group).Wait(0xc00016ec00)
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:40 +0x27
capnproto.org/go/capnp/v3/rpc.NewConn.func1()
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:161 +0x3b
created by capnproto.org/go/capnp/v3/rpc.NewConn
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:160 +0x3f9

goroutine 40 [select]:
capnproto.org/go/capnp/v3/internal/mpsc.(*Rx[...]).Recv(0xc00012c3a0, {0x12f46b8, 0xc00016ec80})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/internal/mpsc/mpsc.go:88 +0x7f
capnproto.org/go/capnp/v3/rpc.(*Conn).send(0xc000136c80)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:426 +0x48
capnproto.org/go/capnp/v3/rpc.(*Conn).backgroundTask.func1()
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:191 +0x6b
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x8d

goroutine 41 [select]:
capnproto.org/go/capnp/v3/rpc/transport.(*pipe).Decode(0x0?, {0x12f46b8, 0xc00016ec80})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/transport/pipe.go:64 +0x86
capnproto.org/go/capnp/v3/rpc/transport.(*transport).RecvMessage(0x0?, {0x12f46b8?, 0xc00016ec80?})
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/transport/transport.go:166 +0xf6
capnproto.org/go/capnp/v3/rpc.(*Conn).receive(0xc000136c80)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:444 +0x78
capnproto.org/go/capnp/v3/rpc.(*Conn).backgroundTask.func1()
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:191 +0x6b
golang.org/x/sync/errgroup.(*Group).Go.func1()
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:57 +0x67
created by golang.org/x/sync/errgroup.(*Group).Go
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:54 +0x8d

goroutine 42 [semacquire]:
sync.runtime_Semacquire(0x0?)
	/usr/local/go/src/runtime/sema.go:56 +0x25
sync.(*WaitGroup).Wait(0x0?)
	/usr/local/go/src/sync/waitgroup.go:136 +0x52
golang.org/x/sync/errgroup.(*Group).Wait(0xc00016ecc0)
	/Users/lthibault/Go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:40 +0x27
capnproto.org/go/capnp/v3/rpc.NewConn.func1()
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:161 +0x3b
created by capnproto.org/go/capnp/v3/rpc.NewConn
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/rpc.go:160 +0x3f9

goroutine 43 [chan receive]:
capnproto.org/go/capnp/v3.(*Future).Struct(0xc0001ac138)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/answer.go:415 +0x65
capnproto.org/go/capnp/v3/rpc/internal/testcapnp.PingPong_echoNum_Results_Future.Struct(...)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/internal/testcapnp/test.capnp.go:207
capnproto.org/go/capnp/v3/rpc_test.TestHandleReturn_regression.func1(0x0?)
	/Users/lthibault/Go/src/capnproto.org/go/capnp/rpc/level0_test.go:1819 +0xd0
testing.tRunner(0xc0001aa820, 0xc0001132b0)
	/usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1486 +0x35f
FAIL	capnproto.org/go/capnp/v3/rpc	10.150s
FAIL

lthibault avatar Jul 29 '22 21:07 lthibault