Skip to content

PgAsyncResultsNotDrained ​

warning native on by default

Group: Probable bugs

Drain all pending PostgreSQL results before another asynchronous query.

Example ​

php
<?php
function f($c) { if(pg_send_query($c,'SELECT 7; SELECT 8')){ pg_get_result($c); pg_send_query($c,'SELECT 9'); } }

Reported:

  • line 2: Drain all pending PostgreSQL results before another asynchronous query.

Detection ​

  • On the same proven connection, a successful pg_send_query of a constant SQL string with at least two statements is followed by fewer fixed pg_get_result calls than statements and another pg_send_query. Also report a second send with no retrieval after any first successful send. Recognize loops until pg_get_result is false as draining; unknown SQL or calls invalidate count proof.
  • Resolve builtin functions, extension classes, constants and method receivers, including aliases and supported named arguments. Inspect reachable operations in one lexical scope with bounded local flow.
  • Emit one finding per violating operation. Never infer policy from names or comments. When the proof is inconclusive, nothing is reported.

Exceptions (no report) ​

  • Exclude shadowed or unresolved symbols, incomplete code, unknown required constants, ambiguous receiver identity and unsupported versions. Reassignment, escaping aliases, and unknown calls invalidate dependent flow facts.
  • Both @custos-ignore PgAsyncResultsNotDrained and @noinspection PgAsyncResultsNotDrained suppress this native rule.

Fix ​

None. A safe repair requires choosing values, error handling, or application behavior.

PHP versions ​

Apply throughout PHP 5.3–8.5 only where the extension API and syntax exist. Do not flag API unavailability through this rule.

Options ​

None. Use normal rule configuration to enable or disable the inspection.

Configure ​

In custos.json:

json
{
  "rules": {
    "PgAsyncResultsNotDrained": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore PgAsyncResultsNotDrained

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.