Skip to content
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

Handle SQL error code 'HY000' in realtime #8106

Merged
merged 1 commit into from
May 9, 2024

Conversation

stnguyen90
Copy link
Contributor

What does this PR do?

SQL can throw an error where the code is a string like 'HY000':

appwrite-realtime | [Error] Type: PDOException
appwrite-realtime | [Error] Message: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
appwrite-realtime | [Error] File: @swoole/library/core/Database/PDOStatementProxy.php
appwrite-realtime | [Error] Line: 44
appwrite-realtime | 
appwrite-realtime | Fatal error: Uncaught TypeError: Utopia\WebSocket\Server::close(): Argument #2 ($code) must be of type int, string given, called in /usr/src/code/vendor/appwrite/server-ce/app/realtime.php on line 523 and defined in /usr/src/code/vendor/utopia-php/websocket/src/WebSocket/Server.php:92
appwrite-realtime | Stack trace:
appwrite-realtime | #0 /usr/src/code/vendor/appwrite/server-ce/app/realtime.php(523): Utopia\WebSocket\Server->close(34577, 'HY000')
appwrite-realtime | #1 [internal function]: {closure}(34577, Object(Appwrite\Utopia\Request))
appwrite-realtime | #2 /usr/src/code/vendor/utopia-php/websocket/src/WebSocket/Adapter/Swoole.php(93): call_user_func(Object(Closure), 34577, Object(Swoole\Http\Request))
appwrite-realtime | #3 [internal function]: Utopia\WebSocket\Adapter\Swoole->Utopia\WebSocket\Adapter\{closure}(Object(Swoole\WebSocket\Server), Object(Swoole\Http\Request))
appwrite-realtime | #4 {main}
appwrite-realtime |   thrown in /usr/src/code/vendor/utopia-php/websocket/src/WebSocket/Server.php on line 92
appwrite-realtime | [2024-05-08 22:04:49 *22786.21] ERROR   php_swoole_server_rshutdown() (ERRNO 503): Fatal error: Uncaught TypeError: Utopia\WebSocket\Server::close(): Argument #2 ($code) must be of type int, string given, called in /usr/src/code/vendor/appwrite/server-ce/app/realtime.php on line 523 and defined in /usr/src/code/vendor/utopia-php/websocket/src/WebSocket/Server.php:92
appwrite-realtime | Stack trace:
appwrite-realtime | #0 /usr/src/code/vendor/appwrite/server-ce/app/realtime.php(523): Utopia\WebSocket\Server->close(34577, 'HY000')
appwrite-realtime | #1 [internal function]: {closure}(34577, Object(Appwrite\Utopia\Request))
appwrite-realtime | #2 /usr/src/code/vendor/utopia-php/websocket/src/WebSocket/Adapter/Swoole.php(93): call_user_func(Object(Closure), 34577, Object(Swoole\Http\Request))
appwrite-realtime | #3 [internal function]: Utopia\WebSocket\Adapter\Swoole->Utopia\WebSocket\Adapter\{closure}(Object(Swoole\WebSocket\Server), Object(Swoole\Http\Request))
appwrite-realtime | #4 {main}
appwrite-realtime |   thrown in /usr/src/code/vendor/utopia-php/websocket/src/WebSocket/Server.php on line 92

but $server->close() expects an integer. This change ensures we only pass an integer into $server->close().

Test Plan

None

Related PRs and Issues

None

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@stnguyen90 stnguyen90 marked this pull request as ready for review May 8, 2024 23:07
app/realtime.php Outdated
Comment on lines 522 to 527
// Handle SQL error code is 'HY000'
$code = $th->getCode();
if (!is_int($code)) {
$code = 500;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this before we create the response, and use $code instead of $th->getCode()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

app/realtime.php Outdated Show resolved Hide resolved
@stnguyen90 stnguyen90 requested a review from abnegate May 9, 2024 02:43
@stnguyen90 stnguyen90 force-pushed the fix-realtime-string-error-code branch from ab2e5c6 to 61a50d7 Compare May 9, 2024 05:55
SQL can throw an error where the code is a string like 'HY000', but
$server->close() expects an integer. This change ensures we only pass
an integer into $server->close().
@stnguyen90 stnguyen90 force-pushed the fix-realtime-string-error-code branch from 61a50d7 to e5f49b4 Compare May 9, 2024 05:55
@abnegate abnegate merged commit 86a822c into refactor-usage-sn May 9, 2024
21 checks passed
@abnegate abnegate deleted the fix-realtime-string-error-code branch May 9, 2024 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants