Closed keegancsmith closed 1 year ago
@samherrmann can't seem to add you as a reviewer, but mind taking a look?
LGTM.
Are any of the new test cases expected to fail with the previous code? If I take your changes in conn_test.go
but not the changes in conn.go
then go test -race ./...
still passes.
yeah, I didn't introduce a test case which caused the old failure. Honestly I won't have time to tinker with that any time soon, but I imagine you can reproduce by creating io.ReadWriteCloser
which blocks on Read and Write until Close is called.
The test cases I introduced were more to ensure I was correctly understanding the reason the send lock in close was introduced + ensuring we tested all possible call code paths.
The sending mutex may be blocked due to the underlying conn blocking. If that happens then we can't call close since close also attempts to hold the sending mutex. Sending mutex is only used for serializing sends and doesn't protect the fields close reads/writes. I believe we introduced locking it so we would return ErrClosed. This commit instead introduces a check in send which rechecks if we have since closed while attempting to send.
Test Plan: expanded the test coverage
Part of https://github.com/sourcegraph/jsonrpc2/issues/69