-
Notifications
You must be signed in to change notification settings - Fork 3
fix(client): code the pre-send failures so callers can replay them #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Mongo; | ||
|
|
||
| /** | ||
| * A failure raised before the command reached the server. | ||
| * | ||
| * Connection validation and the dial that precedes it run ahead of every | ||
| * send, so a failure raised there leaves the command unsent and nothing | ||
| * applied — the one class of failure a caller may safely replay. | ||
| * | ||
| * The distinction is carried by the TYPE and nothing else. A message quotes | ||
| * caller-chosen values, so callers cannot classify on text; and an error code | ||
| * cannot prove it either, because a post-send error response carries the | ||
| * server's own code into an ordinary {@see Exception} — including codes like | ||
| * HostUnreachable that look pre-send. Only the client raises this type, and | ||
| * only before it has sent anything. | ||
| */ | ||
| class UnsentException extends Exception | ||
| { | ||
| public function isUnsentError(): bool | ||
| { | ||
| return true; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Tests; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Utopia\Mongo\Exception; | ||
| use Utopia\Mongo\UnsentException; | ||
|
|
||
| /** | ||
| * Connection validation and the dial before it run ahead of every send, so a | ||
| * failure raised there leaves the command unsent and nothing applied - the one | ||
| * class of failure a caller may safely replay. That distinction was previously | ||
| * legible only in the message text, and a cloud pool consequently surfaced a | ||
| * replayable refusal to clients as a 500 during a backing resize. | ||
| * | ||
| * It is carried by the type and nothing else. A code cannot carry it: a | ||
| * post-send error response is parsed into an ordinary Exception holding the | ||
| * SERVER's code, which includes codes that look pre-send. | ||
| */ | ||
| final class UnsentErrorTest extends TestCase | ||
| { | ||
| public function testAnUnsentFailureIsDistinguishableByType(): void | ||
| { | ||
| $unsent = new UnsentException('Client is not connected to MongoDB'); | ||
|
|
||
| $this->assertTrue($unsent->isUnsentError()); | ||
| $this->assertInstanceOf(Exception::class, $unsent, 'Callers that catch the package exception must still catch it'); | ||
| } | ||
|
|
||
| public function testAPostSendTimeoutIsNotReportedAsUnsent(): void | ||
| { | ||
| $timeout = new Exception('Receive timeout: no data received within reasonable time', 11601); | ||
|
|
||
| $this->assertTrue($timeout->isTimeoutError()); | ||
| $this->assertFalse( | ||
| $timeout->isUnsentError(), | ||
| 'The command was already on the wire, so its outcome is unknown and it must never be replayed blindly', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The reason a code cannot carry this: the server picks it. A response | ||
| * that happens to report HostUnreachable is still a post-send answer, and | ||
| * replaying the operation it answered could apply it twice. | ||
| */ | ||
| public function testAServerErrorResponseIsNeverReportedAsUnsent(): void | ||
| { | ||
| $response = new \stdClass(); | ||
| $response->code = 6; | ||
| $response->codeName = 'HostUnreachable'; | ||
| $response->errmsg = 'host unreachable'; | ||
|
|
||
| $this->assertFalse(Exception::fromResponse($response)->isUnsentError()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.