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

[5.1.x] Fix pgsql non blocking error #5486

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ext-src/swoole_oracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#ifdef SW_USE_ORACLE

using swoole::Coroutine;

static bool swoole_oracle_blocking = true;
void swoole_oracle_set_blocking(bool blocking) {
swoole_oracle_blocking = blocking;
Expand All @@ -49,7 +47,8 @@ sword swoole_oci_stmt_prepare(
OCIStmt *stmtp, OCIError *errhp, const OraText *stmt, ub4 stmt_len, ub4 language, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_prepare");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });

return result;
}
Expand All @@ -64,7 +63,8 @@ sword swoole_oci_stmt_execute(OCISvcCtx *svchp,
ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_execute");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });

return result;
}
Expand All @@ -80,7 +80,8 @@ sword swoole_oci_stmt_fetch(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orie
sword swoole_oci_stmt_fetch2(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orientation, sb4 scrollOffset, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_fetch2");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });

return result;
}
Expand Down
9 changes: 7 additions & 2 deletions ext-src/swoole_pgsql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "thirdparty/php80/pdo_pgsql/php_pdo_pgsql_int.h"
#endif

using swoole::Coroutine;
using swoole::Reactor;
using swoole::coroutine::Socket;
using swoole::coroutine::translate_events_to_poll;
Expand All @@ -42,7 +43,7 @@ static int swoole_pgsql_socket_poll(PGconn *conn, swEventType event, double time

int result = 0;
do {
result = poll(fds, 1, timeout);
result = poll(fds, 1, timeout);
} while (result < 0 && errno == EINTR);

return result > 0 ? 1 : errno == ETIMEDOUT ? 0 : -1;
Expand Down Expand Up @@ -97,7 +98,11 @@ PGconn *swoole_pgsql_connectdb(const char *conninfo) {
return conn;
}

PQsetnonblocking(conn, 1);
if (!swoole_pgsql_blocking && Coroutine::get_current()) {
PQsetnonblocking(conn, 1);
} else {
PQsetnonblocking(conn, 0);
}

SW_LOOP {
int r = PQconnectPoll(conn);
Expand Down
Loading