Repair resolving of longer chains when reconnects happen

This commit is contained in:
Tony Garnock-Jones 2023-10-11 21:03:43 +02:00
parent c8fc52a685
commit cd2d710692
1 changed files with 15 additions and 1 deletions

View File

@ -193,7 +193,21 @@ export function boot(ds: Ref, debug: boolean = false, WebSocketConstructor?: typ
}) when (e()) => {
switch (resolved._variant) {
case "accepted":
resolve(() => resolved.responderSession, more, k);
// Include a call to our e() in the e we pass in to the recursive
// call to resolve(). e() returning non-null is a precondition for
// the call; if that precondition ever changes, we want to NOT
// reevaluate the body of any assertion, so we should test it
// before we do.
//
// Concrete example of a problem that occurs if the `e() && ...`
// isn't there: connected all OK, the websocket disconnects,
// best.value gets set null, the previous assertion of ResolvePath
// at the end of the chain gets reevaluated because
// resolved.responderSession is still non-null, it includes
// best.value!, which is now null, boom. With the call to e(), we
// short circuit and so the assertion becomes null at that point.
//
resolve(() => e() && resolved.responderSession, more, k);
break;
case "Rejected":
k(() => resolved);