rpc/stream/vc: Fix a race in the VC code that sometimes prevents TLS
from properly negotiating.

This race was caused by CL 9932.  It used to be that we set
vc.acceptHandshakeDone at the same time we set vc.handshakeFID (we did
both under a mutex).  This prevented a race where we first accept the
connection, but then before we set vc.handshakeFID we get a packet
and during DispatchPayload we'd call vc.waitForHandshakeLocked which
deadlocks.

In the new code we need to set vc.acceptHandshakeDone in cases where
we aren't creating the handshakeConn at all, so these two lines of
code got separated, causing the race described above.

This change fixes the race by not relying on setting vc.handshakeFID.
In fact the variable is eliminated.  Instead the server requires incomming
handshake and auth connections to have the expected FIDs and returns
errors if they don't (instead of assuming that the first accepted fid
is the handshake fid).

Now we correctly bypass the waitForHandshakeLocked call.

Change-Id: I2db3977827f8d93e17e57c09294c53787a89073e
1 file changed
tree: 20cd82885105f09c7ddef2eafd5739dcdba46a46
  1. cmd/
  2. envvar/
  3. examples/
  4. internal/
  5. lib/
  6. profiles/
  7. services/
  8. test/
  9. .gitignore
  10. AUTHORS
  11. CONTRIBUTORS
  12. LICENSE
  13. PATENTS
  14. README.md
  15. VERSION
README.md

This is the code repository containing a reference implementation of the Vanadium project API.