Commit f002aff
authored
Fix cross-test pollution from engineered homeservers re-using the same server names (fix
### What problem are we trying to solve?
This PR is tackling this problem:
> Many of the faster joins test flakes are due to the homeserver under test failing to contact Complement homeservers after they have been torn down. When this happens, subsequent tests can fail if they use a Complement homeserver that happens to have the same `hostname:port` as one which the homeserver under test has previously marked as offline.
>
> *-- #626
This problem occurs because as an [optimization](#471) we try to share the `deployment` across many tests. To be clear, as a dumb-simple solution, if we created a new `deployment` for each test, we wouldn't run into this issue (but then the tests would be "slow" again).
### What does this PR do?
Spawning from #878 (comment) where I originally thought we could prevent stray requests to a server just from the federation request [authentication](https://spec.matrix.org/v1.18/server-server-api/#authentication) but turns out, it's already doing the right thing. The only thing we can do is compare the `destination` to our server name which [`VerifyHTTPRequest`](https://github.com/matrix-org/gomatrixserverlib/blob/c9c468727353c4835523349dc7c202e5de9a2e37/fclient/request.go#L216-L227) is already doing. And since the crux of this whole thing is that two Complement engineered servers can use the same recycled port and have identical server names (`host.docker.internal:port`), it doesn't help us here. The rest of the public key stuff that is part of federation requests is just for the origin server to sign itself with, for authenticity.
> `destination`: [Added in v1.3] the server name of the receiving server. This is the same as the `destination` field from the JSON described in step 1. For compatibility with older servers, recipients should accept requests without this parameter, but MUST always send it. If this property is included, but the value does not match the receiving server’s name, the receiving server must deny the request with an HTTP status code 401 Unauthorized.
>
> *-- https://spec.matrix.org/v1.18/server-server-api/#authentication*
Instead, this PR takes an alternative route where we instead never re-use the same `server_name` for a Complement engineered homeserver. This means that even if the real homeserver reaches out to the torn-down engineered homeservers, it just hits 'connection refused' instead of a live, unrelated server. No cross-test pollution.
In the context of `tests/msc3902/federation_room_join_partial_state_test.go`, it means the engineered homeserver will never see a [`t.Errorf("Received unexpected PDU", ...)`](https://github.com/matrix-org/complement/blob/bc2b638b11f5b0a068e39ae51f7ac2782070d14f/tests/msc3902/federation_room_join_partial_state_test.go#L77C7-L77C40) problem.
### How do we currently deal with this?
Currently, we try to workaround the stray request problem by making sure the engineered homeserver leaves any rooms it shares with the real homeserver. This means the real homeserver has no logical reason to contact the other server but it's still technically possible that it might reach out because of some queued federation traffic, etc. I find this approach/pattern pretty bad (especially in the way it's currently implemented). See the "Fix" explanation on #878 for more info.
See all of the logic around [`partialStateJoinResult.Destroy`](https://github.com/matrix-org/complement/blob/bc2b638b11f5b0a068e39ae51f7ac2782070d14f/tests/msc3902/federation_room_join_partial_state_test.go#L4399-L4428) and [`WithWaitForLeave`](https://github.com/matrix-org/complement/blob/bc2b638b11f5b0a068e39ae51f7ac2782070d14f/tests/msc3902/federation_room_join_partial_state_test.go#L126-L162) to see how messy this gets and all of the logic that we get to remove because of this new approach.TestPartialStateJoin flakes) (#880)1 parent 589dd56 commit f002aff
1 file changed
Lines changed: 83 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
531 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
532 | 613 | | |
533 | 614 | | |
534 | 615 | | |
535 | 616 | | |
536 | 617 | | |
537 | 618 | | |
538 | 619 | | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
| 620 | + | |
543 | 621 | | |
544 | 622 | | |
545 | 623 | | |
| |||
0 commit comments